Question

I use this code in my views' (which are UserControl) constructors:

this.DataContext = The<Chart1ViewModel>.Instance;

Where the The<> is a generic static per-type singleton storage which also needs to implement INotifyPropertyChanged to notify of it's instance replacement.

I would like to XAML this code like, how can I do that? I have never before did bind anything to a generic static classes.

If I can't, how could I create a Binding to that static class' Instance property?

Was it helpful?

Solution

As far as I know you'll have problems using generics in XAML. Nevertheless you can use static classes. By wrapping a property around the generic you could do something like this:

<Control DataContext="{x:Static The.Chart1ViewModel.Instance}" />
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top