简体   繁体   English

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

[英]How to add .xaml to create a custom Theme on MahApps.Metro

I'm new to WPF in general and now I was trying to make a custom theme, specifically a Dark Mode (using others colors, not the default BaseDark), so I was reading the documentation here: 一般而言,我是WPF的新手,现在我试图制作一个自定义主题,特别是深色模式(使用其他颜色,而不使用默认的BaseDark),因此我在这里阅读文档:

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

But I don't know what to do with it. 但是我不知道该怎么办。 That code is a .xaml, right? 该代码是.xaml,对吗? like BaseDark.xaml referenced in App.xaml 像App.xaml中引用的BaseDark.xaml

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

So, how do I implement it into the project? 那么,如何将其实现到项目中呢? I read here that I had to "create MyCustomAccent.xaml under Styles/Accents folder" but I have no idea how to do that and the post is old 在这里阅读到我必须“在Styles / Accents文件夹下创建MyCustomAccent.xaml”,但我不知道如何执行此操作,并且帖子已过时

So that's the question, how do I add my custom .xaml Theme to my project? 这就是问题,如何将自定义.xaml主题添加到项目中?

I know that later I have to use the ThemeManager.ChangeAppTheme to switch between BaseLight and my CustomDark, I already made a toggle button that does that between BaseLight and BaseDark 我知道以后我必须使用ThemeManager.ChangeAppTheme在BaseLight和我的CustomDark之间进行切换,我已经制作了一个在BaseLight和BaseDark之间进行切换的按钮

This page has a step by step for you: https://mahapps.com/guides/quick-start.html#styling 此页面为您提供了逐步的说明: https : //mahapps.com/guides/quick-start.html#styling

The idea is that you add the styles dictionary to the Window like so: 想法是您将样式字典添加到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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM