XAML binding: binding to the properties of a "global" object

I would like to have one (global, singleton) object in my application that provides many dependency properties. I would like to bind values ​​in XAML to these dependency properties. How can I achieve this so that the syntax of my XAML binding is as simple as possible (in other words, don't always worry about RelativeSource, AncestoryType, etc.).

+7
source share
1 answer

You can use the x: Static markup extension to bind directly to your Singleton, as this is a static property.

For example, if your singleton had a property named "Foo":

<TextBox Text="{x:Static local:YourSingleton.Instance.Foo}" /> 
+7
source

All Articles