如何添加.xaml以在MahApps.Metro上创建自定义主题

时间:2019-05-09 15:38:13

标签: c# mahapps.metro

一般来说,我是WPF的新手,现在我试图制作一个自定义主题,特别是深色模式(使用其他颜色,而不是默认的BaseDark),所以我在这里阅读文档:

https://mahapps.com/guides/styles.html#custom

但是我不知道该怎么办。该代码是.xaml,对吗?类似于App.xaml

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

那么,如何将其实现到项目中?我读过here,我必须“在Styles / Accents文件夹下创建MyCustomAccent.xaml”,但我不知道该怎么做,而且帖子已过时

这就是问题,如何将自定义.xaml主题添加到项目中?

我知道以后我必须使用ThemeManager.ChangeAppTheme在BaseLight和我的CustomDark之间切换,我已经制作了一个在BaseLight和BaseDark之间执行切换的按钮

1 个答案:

答案 0 :(得分:0)

此页面为您提供了分步操作:https://mahapps.com/guides/quick-start.html#styling

想法是您将样式字典添加到Window中,如下所示:

<Application x:Class="WpfApplication.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             StartupUri="MainWindow.xaml">
  <Application.Resources>
    <ResourceDictionary>
      <ResourceDictionary.MergedDictionaries>
        <!-- MahApps.Metro resource dictionaries. Make sure that all file names are Case Sensitive! -->
        <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" />
        <!-- Accent and AppTheme setting -->
        <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>
</Application>