Ok, this is going to seem really stupid, cause it was, but I thought I would share my pain incase someone has the same issue.
A while back I blogged about how to create a Convention Based View Model Location using Ninject in a MVVM/Silverlight Application in this post I talk about how to create a VMLocator, but to be honest my issue would also be visible if you rolled your own so you do not need to review my prior post if you do not want.
My issue was that I created a child window in my Silverlight application and setup my binding for the VMLocator as normal
DataContext="{Binding Source={StaticResource VMLocator}, Converter={StaticResource VMIndexerConverter}}"
However, when I created the instance of the View the VMLocator was not being invoked and I was perplexed. After talking it over w/ a co-worker it dawned on me that in my overloaded constructor in my View I did NOT setup the call to InitializeComponent(); correctly, OK i plan forgot to add it. Once I added the call to InitializeComponent(); everything just worked and the world was a happy place.
The moral of the story is this, if you are trying to use the VMLocator pattern via setting the DataContext in XAML you MUST make sure you have a call to InitializeComponent(); in your constructor or you will not get the results you expected.
Till next time,
Posted
08-04-2011 11:44 AM
by
Derik Whittaker