wpf 应用 MahApps.Metro Dark 主题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21362935/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 10:36:41  来源:igfitidea点击:

Applying MahApps.Metro Dark theme

c#.netwpfxamlmahapps.metro

提问by Chathuranga Chandrasekara

I am relatively new to WPF and I am trying to apply Windows Metro Dark theme to my entire application.

我对 WPF 比较陌生,我正在尝试将 Windows Metro Dark 主题应用于我的整个应用程序。

I used the following in my Apps.xaml and I can see the Windows Metro Light theme properly.

我在 Apps.xaml 中使用了以下内容,我可以正确地看到 Windows Metro Light 主题。

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

Now I want to change the theme to Dark. I understand I can always use,

现在我想将主题更改为 Dark。我明白我可以一直使用,

ThemeManager.ChangeTheme()

ThemeManager.ChangeTheme()

But I believe there should be a way to do this with XAML effective to all the windows of the application.

但我相信应该有一种方法可以使用 XAML 对应用程序的所有窗口有效。

My Question :Can someone point me how to do this without using ThemeManager in source code?

我的问题:有人可以指出我如何在源代码中不使用 ThemeManager 的情况下做到这一点吗?

回答by har07

Try to use BaseDarkinstead of BaseLight. Try to change this line :

尝试使用BaseDark而不是BaseLight. 尝试更改此行:

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

to this :

对此:

<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseDark.xaml" />

That did the trick for me. Screenshot of my application using MahApps BaseDark and BaseLight accents:

这对我有用。我的应用程序使用 MahApps BaseDark 和 BaseLight 口音的屏幕截图:

BaseDarkenter image description hereBaseLightenter image description here

BaseDark 在此处输入图片说明BaseLight在此处输入图片说明