gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 16:08:29 25 4
gpt4 key购买 nike

我正在使用 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 时,一切正常...

最佳答案

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

通用资源.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>

关于WPF MahApps.Metro - 将 ResourceDictionaries 放在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15962184/

25 4 0