Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVVM Light ViewModelLocator + ResourceDictionaries

I originally posted this message on the MVVM Light CodePlex page but haven't heard a response yet so I'm hoping someone here can help me. Here is the question:

I recently started playing with MVVM (new to WPF too - quite the learning curve for all of this) and everything was working great with my ViewModelLocator instance and binding design-time for VS2010 until I started using the MetroToolkit provided on CodePlex. Before utilizing the toolkit, I had the following:

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

All of my views were binding great and everything looked really good. I was surprised at just how easy someone without MVVM (or MVC) experience could get up and running. Then I hit a snag of MetroToolkit requiring merged resource dictionaries and now no matter what I try I can't get VS to find my ViewModelLocator again inside App.xaml. 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 have tried giving the resource dictionary a key, adding the line outside of the area (above and below - throws nasty and very unhelpful errors) and can't get it to find my VM Locator. It works immediately when I remove the block from App.xaml, but based on my very limited knowledge of WPF I need those if I want the styles to be available to all views in my application.

Any thoughts? This has been driving me crazy for a few hours now.

like image 355
Scott Salyer Avatar asked May 27 '11 18:05

Scott Salyer


1 Answers

yep...I just saw this the other day...You have to put a 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...this is 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>
like image 192
ecathell Avatar answered Nov 06 '22 15:11

ecathell