I'm having a strange issue, and I can't seem to find any answers on.
I'm building a Metro Store App with Visual Studio 2012 using MVVM Light through NuGet.
When designing and adding the data context xaml code, studio gives me the red swiggly with the error "Object reference not set to an instance of an object".
DataContext={Binding MainVM, Source={StaticResource Locator}}
I finally narrowed it down to the inheritance in my viewmodel. I have a base viewmodel that all my viewmodels inherit from declared as such:
public class BaseViewModel : ViewModelBase
{
}
Then obviously all my viewmodels as such:
public class MainViewModel : BaseViewModel
{
}
Now, at runtime everything works perfectly fine (which is confusing to me), but the design mode breaks.
However, if I remove the inheritance and have my viewmodels directly inherit the ViewModelBase, everything is fine in design mode:
public class MainViewModel : ViewModelBase
{
}
I thought that perhaps something in the code was causing an issue, so I commented everything out except what was required to compile and still receive the same result.
Anyone seem to have this issue, or know what I might be doing wrong by this? I normally use this same pattern when working on Silverlight or WPF applications using MVVM and things seem fine there.
Just a sidenote, my ViewModelLocator does have a MainVM property that returns the MainViewModel class.
UPDATE After reading LBugnion and Will's comments I was getting ready to debug the design mode when I noticed I goofily had forgotten to comment out my code in the BaseViewModel. I did find that there was breaking code in there. Design mode did not like the following line:
private CoreDispatcher UIDispatcher = Windows.UI.Core.CoreWindow.GetForCurrentThread().Dispatcher;
Which I was using to update the UI thread in code. I'm guessing (which someone more experienced may chime in) there is no UI thread in design mode?
Normally I use the "IsInDesignMode" property to make my viewmodels almost non-functional for design, but apparently forgot to do so here, so I changed the line above to
private CoreDispatcher UIDispatcher = IsInDesignModeStatic ? null : Windows.UI.Core.CoreWindow.GetForCurrentThread().Dispatcher;
My goof