Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You could use a static you can read from and bind to, using the x:Static in your XAML. I do not like doing static global settings as it's more of an anti-pattern.</p> <p>I think you should look into inversion of control/dependency injection. There are many IoC containers out there, but I usually use Unity for my dependency injection. It's available at <a href="http://prism.codeplex.com" rel="nofollow noreferrer">http://prism.codeplex.com</a></p> <p>Using IoC, you could register you settings class, and within your VM that need the data, they can easily pull out the settings you want. Your code would look something similar to this (if using unity).</p> <pre><code>var vm = container.Resolve&lt;SomeViewModel&gt;(); public class SomeViewModel { public SomeViewModel(IUnityContainer container) { ISomeSettings settings = container.Resolve&lt;ISomeSettings&gt;(); } } </code></pre> <p><strong>EDIT: Or here is another solution you may be looking for:</strong></p> <p>Create your singleton:</p> <pre><code>class GlobalSettings : ViewModel { private Thickness m_globalGirth; private static GlobalSettings m_instance = new GlobalSettings(); public GlobalSettings() { GlobalGirth = new Thickness(2, 2, 2, 2); } public Thickness GlobalGirth { get { return m_globalGirth; } set { m_globalGirth = value; InvokePropertyChanged("GlobalGirth"); } } public static GlobalSettings Instance { get { return m_instance; } set { m_instance = value; } } } </code></pre> <p>Then setup your bindings:</p> <pre><code>&lt;Window x:Class="WpfApplication3.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:WpfApplication3="clr-namespace:WpfApplication3" Title="Window1" Height="300" Width="300" MouseDoubleClick="Window_MouseDoubleClick"&gt; &lt;Window.Resources&gt; &lt;WpfApplication3:GlobalSettings x:Key="settings" /&gt; &lt;/Window.Resources&gt; &lt;Grid&gt; &lt;Border BorderThickness="{Binding Source={StaticResource settings}, Path=Instance.GlobalGirth}" BorderBrush="Black" Width="100" Height="100" /&gt; &lt;/Grid&gt; &lt;/Window&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload