Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF MahApps.Metro - Where to put ResourceDictionaries?

I'm using MahApps.Metro, version 0.11.0.9-ALPHA for .NET 4.5. and want to know the best way to reference their resource dictionaries.

I was told that I shouldn't reference them as merged dictionaries in App.xaml. If that's not the case, do I need to add them as Window.Resources for every window?

I was doing this:

    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colours.xaml" />
            <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
            <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
            <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/Red.xaml" />
            <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseLight.xaml" />
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>

</Application.Resources>

The problem with this is that some controls act funky, for example the minimize, maximize and close buttons on the window appear as black blocks without text. When I reference these resource dictionaries as Window.Resources, it all works fine...

like image 805
Patrick Bounaix Avatar asked Apr 12 '13 02:04

Patrick Bounaix


1 Answers

I simply use a shared resource dictionary which is referenced by every window.

GeneralResources.xaml:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colours.xaml" />
        <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
        <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
        <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/Blue.xaml" />
        <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseLight.xaml" />
        <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.AnimatedTabControl.xaml" />
    </ResourceDictionary.MergedDictionaries>

    <other shared resources... />
</ResourceDictionary>

Each window:

<Window.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="GeneralResources.xaml" />
        </ResourceDictionary.MergedDictionaries>

        <other window resources... />
   </ResourceDictionary>
</Window.Resources>
like image 59
Rich Avatar answered Nov 15 '22 07:11

Rich