WPF MahApps.Metro - 在哪里放置ResourceDictionaries?

时间:2013-04-12 02:38:52

标签: wpf xaml microsoft-metro resourcedictionary

我正在使用MahApps.Metro,版本0.11.0.9-ALPHA for .NET 4.5。并想知道引用其资源词典的最佳方式。

我被告知我不应该将它们作为App.xaml中的合并字典引用。如果不是这样,我是否需要为每个窗口添加它们作为Window.Resources?

我这样做:     

    <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>

这个问题是有些控件很时髦,例如窗口上的最小化,最大化和关闭按钮显示为没有文本的黑色块。当我将这些资源字典引用为Window.Resources时,一切正常......

1 个答案:

答案 0 :(得分:7)

我只使用每个窗口引用的共享资源字典。

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>

每个窗口:

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

        <other window resources... />
   </ResourceDictionary>
</Window.Resources>