MVVM Light ViewModelLocator + ResourceDictionaries

I originally posted this message on the MVVM Light CodePlex page, but have not yet received a response, so I hope someone here can help me. Here is the question:

I recently started playing with MVVM (new to WPF too - a pretty learning curve for all this), and everything worked fine with my ViewModelLocator instance and the binding time to VS2010, until I started using the MetroToolkit provided in CodePlex. Before using the toolkit, I had the following:

<Application.Resources> <local:ViewModelLocator x:Key="Locator" d:IsDataSource="True" /> </Application.Resources> 

All of my views were binding, and everything looked really good. I was surprised at how easy a person with no MVVM (or MVC) experience could get up and work. Then I fell into the MetroToolkit trap that required merged resource dictionaries, and now, no matter what I try, I can not get VS to find my ViewModelLocator inside App.xaml again. Here is the new markup:

 <Application.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="/MetroToolkit;component/Themes/Dark/Colors.xaml" /> <ResourceDictionary Source="/MetroToolkit;component/Themes/Dark/Animations.xaml" /> <ResourceDictionary Source="/MetroToolkit;component/Themes/Dark/Geometry.xaml"/> <ResourceDictionary Source="/MetroToolkit;component/Themes/Dark/Generic.xaml"/> <ResourceDictionary Source="/MetroToolkit;component/Themes/Dark/Buttons.xaml" /> <ResourceDictionary Source="/MetroToolkit;component/Themes/Dark/Scrollbar.xaml" /> <ResourceDictionary Source="/MetroToolkit;component/Themes/Dark/Scrollviewer.xaml" /> <ResourceDictionary Source="/MetroToolkit;component/Themes/Dark/RadioButton.xaml" /> <ResourceDictionary Source="/MetroToolkit;component/Themes/Dark/ProgressBar.xaml" /> <ResourceDictionary Source="/MetroToolkit;component/Themes/Dark/ContextMenu.xaml" /> <ResourceDictionary Source="/MetroToolkit;component/Themes/Dark/Tooltip.xaml" /> <ResourceDictionary Source="/MetroToolkit;component/Themes/Dark/Checkbox.xaml" /> <ResourceDictionary Source="/MetroToolkit;component/Themes/Dark/Headings.xaml" /> <ResourceDictionary Source="/MetroToolkit;component/Themes/Dark/Textbox.xaml" /> <ResourceDictionary Source="/MetroToolkit;component/Themes/Dark/Combobox.xaml" /> <ResourceDictionary Source="/MetroToolkit;component/Themes/Dark/Slider.xaml" /> <ResourceDictionary Source="/MetroToolkit;component/Themes/Dark/Expander.xaml" /> <ResourceDictionary Source="/MetroToolkit;component/Themes/Dark/TabControl.xaml" /> </ResourceDictionary.MergedDictionaries> <local:ViewModelLocator x:Key="Locator" d:IsDataSource="True" /> </ResourceDictionary> </Application.Resources> 

I tried to give the resource dictionary a key by adding a line outside the scope (above and below - it throws unpleasant and very useless errors) and cannot make it find my VM locator. It works right away when I remove a block from App.xaml, but based on my very limited WPF knowledge, I need these if I want the styles to be accessible to all views in my application.

Any thoughts? This led me crazy for hours.

+6
source share
1 answer

yep ... I just saw this the other day ... you have to put the resource dictionary inside ...

  <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="/MetroToolkit;component/Themes/Dark/Colors.xaml" /> <ResourceDictionary Source="/MetroToolkit;component/Themes/Dark/Animations.xaml" /> <ResourceDictionary Source="/MetroToolkit;component/Themes/Dark/Geometry.xaml"/> <ResourceDictionary Source="/MetroToolkit;component/Themes/Dark/Generic.xaml"/> <ResourceDictionary Source="/MetroToolkit;component/Themes/Dark/Buttons.xaml" /> <ResourceDictionary Source="/MetroToolkit;component/Themes/Dark/Scrollbar.xaml" /> <ResourceDictionary Source="/MetroToolkit;component/Themes/Dark/Scrollviewer.xaml" /> <ResourceDictionary Source="/MetroToolkit;component/Themes/Dark/RadioButton.xaml" /> <ResourceDictionary Source="/MetroToolkit;component/Themes/Dark/ProgressBar.xaml" /> <ResourceDictionary Source="/MetroToolkit;component/Themes/Dark/ContextMenu.xaml" /> <ResourceDictionary Source="/MetroToolkit;component/Themes/Dark/Tooltip.xaml" /> <ResourceDictionary Source="/MetroToolkit;component/Themes/Dark/Checkbox.xaml" /> <ResourceDictionary Source="/MetroToolkit;component/Themes/Dark/Headings.xaml" /> <ResourceDictionary Source="/MetroToolkit;component/Themes/Dark/Textbox.xaml" /> <ResourceDictionary Source="/MetroToolkit;component/Themes/Dark/Combobox.xaml" /> <ResourceDictionary Source="/MetroToolkit;component/Themes/Dark/Slider.xaml" /> <ResourceDictionary Source="/MetroToolkit;component/Themes/Dark/Expander.xaml" /> <ResourceDictionary Source="/MetroToolkit;component/Themes/Dark/TabControl.xaml" /> <ResourceDictionary> <local:ViewModelLocator x:Key="Locator" d:IsDataSource="True" /> </ResourceDictionary> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> 

** EDIT Sorry ... Fixed it now ... I was going from memory ... the way it is in mine.

 <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="Dictionaries/converters.xaml" /> <ResourceDictionary Source="assets/styles.xaml" /> <ResourceDictionary Source="assets/sdkstyles.xaml" /> <ResourceDictionary Source="assets/corestyles.xaml" /> <ResourceDictionary> <local:ApplicationResources x:Key="ApplicationResources" /> </ResourceDictionary> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> 
+13
source

Source: https://habr.com/ru/post/889232/


All Articles