5

我正在使用适用于 .NET 4.5 的 MahApps.Metro 版本 0.11.0.9-ALPHA。并想知道引用他们的资源字典的最佳方式。

有人告诉我,我不应该将它们作为 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 时,一切正常...

4

1 回答 1

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>
于 2013-04-12T09:17:00.703 回答