当前位置:网站首页>C# WPF UI框架MahApps切换主题
C# WPF UI框架MahApps切换主题
2022-04-23 00:33: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
边栏推荐
- According to this effective method, UI automation testing is so simple
- 倍福EL5101模块获取光栅尺反馈位置并绑定到NC轴配置
- 洛谷P2241统计方形
- 植被物候參數遙感研究進展(好文分享)
- Mitsubishi fx5u configures iebasic setting of mr-je-c servo driver
- Misunderstanding of indexlookup
- MySQL -- data type
- 【图像分类】用最简单的代码复现SENet,初学者一定不要错过(pytorch)
- 倍福常用产品模块型号配置参数
- [essay contest] the first essay contest of tidb community column. Come and gather all the surrounding areas at one time!
猜你喜欢

Absolute positioning does not use left, right, top, bottom and other attributes
![[classification de l'image] - Venez et séchez ce bol d'efficientnet](/img/74/8c811ba94e29947d5c2ae0e1c05131.png)
[classification de l'image] - Venez et séchez ce bol d'efficientnet

ArcGIS 城市生活区用地适宜性评价(三)

倍福两台CX控制器之间添加路由

MySQL运行workbench报错TRunTimeError

Addition, deletion, modification and query of MySQL table (Advanced)

JS - process and split the data of consecutive months

(transfer) how winscp (SSH FTP client) generates the key to log in Linu

ArcGIS 城市生活区用地适宜性评价(四)

接口文档生成工具ApiPost 绝了
随机推荐
(to) excel 2016 does not have enough memory or disk space to open excel
Beifu scope view oscilloscope reads the signal of configuration IO
ArcGIS 城市生活区用地适宜性评价(二)
Dynamic programming: grouping knapsack problem
【图像分类】——来来来,干了这碗EfficientNet实战(Pytorch)
洛谷P2241统计方形
(transfer) Aspose Documentbuilder II of words Programming Guide
【图像分类】用最简单的代码复现SENet,初学者一定不要错过(pytorch)
Beifu el5101 module obtains the feedback position of the grating ruler and binds it to the NC axis configuration
Research progress of Lake remote sensing (Overview)
(turn to) C # best tool set: IDE, analysis, automation tools, etc
在Google工作的十年,也是我开心的十年
Usage of while (n -- > 0)
TiDB 在连锁快餐企业丨海量交易与实时分析的应用探索
[image classification] reproduce senet with the shortest code. Xiaobai must be collected (keras, tensorflow2. X)
Unittest单元测试(六)
Object size and pointer compression -- JVM
湖泊的水色、水环境、水文遥感的区别
[essay contest] the first essay contest of tidb community column. Come and gather all the surrounding areas at one time!
ArcMap spatial connection and intersection tool