当前位置:网站首页>C# WPF UI框架MahApps切换主题
C# WPF UI框架MahApps切换主题
2022-04-23 03:02:00 【dotNET跨平台】
概述
本指南将向您介绍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
技术群:添加小编微信并备注进群
小编微信:mm1552923
公众号:dotNet编程大全
版权声明
本文为[dotNET跨平台]所创,转载请带上原文链接,感谢
https://blog.csdn.net/sd7o95o/article/details/124357629
边栏推荐
- Résumé du gestionnaire de projet du système d'information Chapitre VI gestion des ressources humaines du projet
- Source code and some understanding of employee management system based on polymorphism
- Step principle of logical regression in machine learning
- Airtrack cracking wireless network password (Dictionary running method)
- Error installing Mongo service 'mongodb server' on win10 failed to start
- Navicat failed to connect to Oracle Database: cannot load OCI DLL, 87: instant client package is
- Kubernetes - detailed explanation of pod
- 国产轻量级看板式Scrum敏捷项目管理工具
- [format] simple output (2)
- L2-006 树的遍历(中后序确定二叉树&层序遍历)
猜你喜欢
【Hcip】OSPF常用的6种LSA详解
ROP Emporium x86_ 64 7 ~ 8 questions
The input of El input input box is invalid, and error in data(): "referenceerror: El is not defined“
Linux Redis——Redis 数据库缓存服务
L2-006 樹的遍曆(中後序確定二叉樹&層序遍曆)
[hcip] detailed explanation of six LSAS commonly used by OSPF
树莓派开发笔记(十二):入手研华ADVANTECH工控树莓派UNO-220套件(一):介绍和运行系统
Domestic lightweight Kanban scrum agile project management tool
FileNotFoundError: [Errno 2] No such file or directory
Huashu "deep learning" and code implementation: 01 Linear Algebra: basic concepts + code implementation basic operations
随机推荐
The usage of case when and select case when is very easy to use
Codeforces round 784 (Div. 4) (a - H)
How can enterprises with major hazard installations ensure the completion of the digital construction task of double prevention mechanism by the end of the year
leangoo脑图-共享式多人协作思维导图工具分享
Get together to watch (detailed version) eat a few cents a day
Table space capacity query and expansion of Oracle Database
Log cutting - build a remote log collection server
AC & A2C & A3C
The space between the left and right of the movie ticket seats is empty and cannot be selected
ele之Table表格的封装
Practice of industrial defect detection project (III) -- Based on FPN_ PCB defect detection of tensorflow
Difference between relative path and absolute path (often asked in interview)
Les derniers noeuds K de la liste jz22
tf. keras. layers. Conv? D function
Dynamic sequence table + OJ
Close the computer port
《信息系统项目管理师总结》第四章 项目成本管理
What is the difference between varchar and char?
tf. keras. layers. Timedistributed function
Assembly learning Chapter III of assembly language (Third Edition) written by Wang Shuang