I have been trying to understand the correct way to set my DataContext. I have been doing it in code behind, but have been looking for a better way to do it with DataBinding.
Yesterday, I tried adding it to my local resources in my App() constructor, like this:
Resources.Add("MyGlobalViewModel", mgvm);
My application also had some resources defined in a ResourceDictionary in it’s own xaml file.
Unfortunately, I chose to add my resources in code before I called InitializeComponent(), and as a result, my additions were removed.
Once I did that I was able to set my data context as
<… DataContext={Binding {StaticResource MyGlobalViewModel}} … >
No comments:
Post a Comment