当前位置:网站首页>C# WPF UI框架MahApps切换主题
C# WPF UI框架MahApps切换主题
2022-06-09 22:49:00 【用户9127601】
概述
本指南将向您介绍MahApps.Metro如何切换主题,所有的MahApps.Metro的主题都包含在单独的资源字典中。
如何使用主题
您可以在以下可用配色方案中进行选择:
"Red", "Green", "Blue", "Purple", "Orange", "Lime", "Emerald", "Teal", "Cyan", "Cobalt", "Indigo", "Violet", "Pink", "Magenta", "Crimson", "Amber", "Yellow", "Brown", "Olive", "Steel", "Mauve", "Taupe", "Sienna"这些基本主题:
"Light", "Dark"通过App.xaml使用主题:
最快的方法是在App.xaml中指定主题资源
<Application x:Class="SampleApp"
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" />
<!-- Theme setting -->
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Themes/Light.Blue.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>通过主题管理器使用主题:
MahApps.Metro有一个ThemeManager类,可以使用后台代码更改主题。可以在一行中完成,如下所示:
using ControlzEx.Theming;
public partial class SampleApp : Application
{
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
// Set the application theme to Dark.Green
ThemeManager.Current.ChangeTheme(this, "Dark.Green");
}
}在与应用程序主窗口不同的窗口上
和MahApps在一样,对于MetroWindow,你可以有不同的主题。主窗口或任何其他MetroWindows将在应用程序中保留指定的主题。
<Controls:MetroWindow.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Themes/Dark.Red.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Controls:MetroWindow.Resources>您也可以使用TheManager执行此操作,如下所示:
using ControlzEx.Theming;
public partial class MainWindow : MetroWindow
{
public void MainWindow()
{
InitializeComponent();
// Set the window theme to Dark.Red
ThemeManager.Current.ChangeTheme(this, "Dark.Red");
}
}创建自定义主题
MahApps的另一个不错的功能。Metro将使用自定义创建的主题或运行时创建的主题。
声明
翻译自:https://mahapps.com/docs/themes/usage#on-a-window-different-to-your-applications-main-window
边栏推荐
- [Title brushing] longest increasing subsequence
- 从零开始实现lmax-Disruptor队列(二)多消费者、消费者组间消费依赖原理解析
- 2022 practice questions and mock exam of quality controller municipal direction general basic (quality controller) examination
- OpenHarmony RISC-V 轻量系统移植—润和W800移植分享
- 双塔模型:ERNIE-Gram预训练精排Matching
- Understand the execution principle of show create table
- 2022 operation of simulated examination platform for examination question bank of pillar special operation certificate for metal and nonmetal mines
- Exness: twitter said that it would continue to share data with musk and conduct shareholder voting at the end of July or early August
- 什么是分布式软件系统
- "Leak detection and vacancy filling" Android internship interview knowledge points (II)
猜你喜欢

Implementing Lmax disruptor queue from scratch (II) analysis of consumption dependency principle among multiple consumers and consumer groups

STM32 drive relay stm32f103rct6 drives IO port based on register and library function

荐书 | 即使是来自星星的你,我也想去靠近

cadence SPB17.4 - allegro - use keyboard move part on grid offset by our setting

2022爱分析· 隐私计算厂商全景报告 | 爱分析报告

Explanation of leetcode UHF questions (I)

在线文本字符串批量替换工具

黄希庭:心理学的研究要走中国人自己的道路,要做中国化的心理学研究

"Leak detection and vacancy filling" Android internship interview knowledge points (II)

模型部署简述
随机推荐
cadence SPB17.4 - allegro - Move With Dynamic Alignment ON/OFF
2022爱分析· 隐私计算厂商全景报告 | 爱分析报告
香橙派H3烧录Uboot,远程加载zImage,dtb,rootfs
IEEE 754浮点数标准详解
QNX system learning
荐书 | 即使是来自星星的你,我也想去靠近
2022金属非金属矿山支柱特种作业证考试题库模拟考试平台操作
又一重磅内容|海外现金贷产品形态及风控措施
Autre contenu lourd | formes de produits et mesures de contrôle des risques pour les prêts en espèces à l'étranger
记一次应急排查“新“路历程
qnx系统学习
Anatomy of illusory rendering system (15) - XR topic
PCBToolkit初步使用
Book club recruits | let's read "Mr. toad goes to see a psychologist"
这知识我没见过--MySQL 服务演进
马志强:语音识别技术研究进展和应用落地分享丨RTC Dev Meetup
STM32驱动继电器 STM32F103RCT6基于寄存器和库函数驱动IO口
Getting to know websocket
服务器运维环境安全体系(下篇)
Leetcode(力扣)超高頻題講解(一)