当前位置:网站首页>C WPF UI framework mahapps switching theme
C WPF UI framework mahapps switching theme
2022-04-23 03:08:00 【Dotnet cross platform】
summary
This guide will introduce you to MahApps.Metro How to switch themes , be-all MahApps.Metro All topics are included in a separate resource dictionary .
How to use themes
You can choose from the following available color schemes :
"Red", "Green", "Blue", "Purple", "Orange", "Lime", "Emerald", "Teal", "Cyan", "Cobalt", "Indigo", "Violet", "Pink", "Magenta", "Crimson", "Amber", "Yellow", "Brown", "Olive", "Steel", "Mauve", "Taupe", "Sienna"
These basic themes :
"Light", "Dark"
adopt App.xaml Use theme :
The fastest way is to App.xaml Specify the topic resource in
<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>

Use themes through the theme manager :
MahApps.Metro There is one ThemeManager class , You can use background code to change the theme . Can be done in one line , As shown below :
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");
}
}
On a different window from the main application window
and MahApps In the same , about MetroWindow, You can have different themes . Main window or any other MetroWindows The specified theme will be retained in the application .
<Controls:MetroWindow.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Themes/Dark.Red.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Controls:MetroWindow.Resources>
You can also use the TheManager Do this , As shown below :
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");
}
}
Create a custom theme
MahApps Another nice feature of .Metro A custom created theme or a runtime created theme will be used .
Statement
Translated from :https://mahapps.com/docs/themes/usage#on-a-window-different-to-your-applications-main-window
Technology Group : Add Xiaobian wechat and comment into the group
Xiaobian wechat :mm1552923
official account :dotNet Programming
版权声明
本文为[Dotnet cross platform]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230301333211.html
边栏推荐
- 7-11 rearrange the linked list (25 points)
- 一套关于 内存对齐 的C#面试题,做错的人很多!
- Dynamic sequence table + OJ
- Blazor University (11)组件 — 替换子组件的属性
- 队列的存储和循环队列
- [software testing] understand the basic knowledge of software testing
- Laravel's own paging query
- TP5 where query one field is not equal to multiple values
- 先中二叉建树
- ASP. Net and ASP NETCORE multi environment configuration comparison
猜你喜欢

How does Microsoft solve the problem of multiple programs on PC side -- internal implementation

MAUI初体验:爽

Source generator actual combat

Laravel new route file

AspNetCore配置多环境log4net配置文件
![[software testing] understand the basic knowledge of software testing](/img/ff/8fcd4b88de28505989aaf517d16113.png)
[software testing] understand the basic knowledge of software testing

最通俗易懂的依赖注入与控制反转

准备一个月去参加ACM,是一种什么体验?
![[new version release] componentone added Net 6 and blazor platform control support](/img/08/71e7328f685a5cdd584f1bfdce5f2a.png)
[new version release] componentone added Net 6 and blazor platform control support

Opencv combines multiple pictures into video
随机推荐
MYSQL_ From mastery to abandonment
一套关于 内存对齐 的C#面试题,做错的人很多!
基于.NetCore开发博客项目 StarBlog - (1) 为什么需要自己写一个博客?
如果通过 C# 实现对象的深复制 ?
Service avalanche effect
Due to 3 ²+ four ²= five ², Therefore, we call '3,4,5' as the number of Pythagorean shares, and find the array of all Pythagorean shares within n (including n).
腾讯视频VIP会员,周卡特价9元!腾讯官方直充,会员立即生效!
建立与遍历二叉树
The most easy to understand dependency injection and control inversion
Dynamic sequence table + OJ
編碼電機PID調試(速度環|比特置環|跟隨)
Thoughts on the 2022 national network security competition of the national secondary vocational group (only one idea for myself) - network security competition questions (9)
准备一个月去参加ACM,是一种什么体验?
Small companies don't make formal offers
使用两种方法来解决“最大回文数乘积”问题
Basic SQL (VIII) data update operation practice
Openfeign service call
C syntax pattern matching [switch expression]
.NET7之MiniAPI(特别篇):.NET7 Preview3
Maui initial experience: Cool