Adding a ViewModelLocator and Merged Dictionaries to App.xaml
.NET,
MVVM,
Phone,
Silverlight,
Technical stuff,
Windows Phone,
Work,
WPF
See comments
I guess this is one of these places where using Blend is an advantage… since I do these operations mostly with the help of the tool, the XAML is generated and I don’t need to think about it too much.
There is a trick when you add objects (for example Styles or a ViewModelLocator) to App.xaml when it already has merged resource dictionaries. The syntax is a bit convoluted, so here we go:
<Application.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="Skins/Brushes.xaml"/> </ResourceDictionary.MergedDictionaries> <vm:ViewModelLocator x:Key="Locator" d:IsDataSource="True" /> </ResourceDictionary> </Application.Resources>
So yeah, the trick is to put the ViewModelLocator (or any other object for that matter) within the ResourceDictionary tag…
HTH,
Laurent