加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

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

发布时间:2020-12-14 02:01:09 所属栏目:Windows 来源:网络整理
导读:我正在使用MahApps.Metro,版本0.11.0.9-ALPHA for .NET 4.5.并想知道引用其资源词典的最佳方式. 有人告诉我,我不应该在App.xaml中将它们作为合并字典引用.如果不是这样,我是否需要为每个窗口添加它们作为Window.Resources? 我这样做: ???? ResourceDiction
我正在使用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时,一切正常……

解决方法

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

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>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读