当前位置:网站首页>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
边栏推荐
- 宁德时代地位不保?
- c#可变参数params的介绍
- 建立与遍历二叉树
- Thoughts on the 2022 national network security competition of the national secondary vocational group (only one idea for myself) - network security competition questions (10)
- Use DFS to solve the problem of "number of dictionary rows"
- C# 读写二进制文件
- The whole network is the most complete. How to do interface automation test? Proficient in interface automation test details
- Aspnetcore configuration multi environment log4net configuration file
- Distributed system services
- Notes sur le développement de la tarte aux framboises (XII): commencer à étudier la suite UNO - 220 de la tarte aux framboises de contrôle industriel advantech (i): Introduction et fonctionnement du s
猜你喜欢
ASP.NET 6 中间件系列 - 条件中间件
Thoughts on the 2022 national network security competition of the national secondary vocational group (only one idea for myself) - network security competition questions (7)
最通俗易懂的依赖注入之生命周期
MYSQL05_ Ordr by sorting, limit grouping, group by grouping
TP5 email (2020-05-27)
Introduction and use of openfeign component
Cherno_ Game engine series tutorial (5): 101~
在.NE6 WebApi中使用分布式缓存Redis
MAUI初体验:爽
Thoughts on the 2022 national network security competition of the national secondary vocational group (only one idea for myself) - network security competition questions (8)
随机推荐
The backtracking of stack is used to solve the problem of "the longest absolute path of file"
Xamarin效果第二十一篇之GIS中可扩展浮动操作按钮
LNMP MySQL allows remote access
FileNotFoundError: [Errno 2] No such file or directory
Recursion - outputs continuously increasing numbers
Binary tree
Fight leetcode again (290. Word law)
.NET7之MiniAPI(特别篇):.NET7 Preview3
Swap the left and right of each node in a binary tree
ASP. Net 6 middleware series - execution sequence
Openfeign service call
Opencv combines multiple pictures into video
Introduction and use of openfeign component
Basic SQL (VIII) data update operation practice
What kind of experience is it to prepare for a month to participate in ACM?
The most detailed in the whole network, software testing measurement, how to optimize software testing cost and improve efficiency --- hot
Judge whether there is a leap year in the given year
利用栈的回溯来解决“文件的最长绝对路径”问题
队列的存储和循环队列
ASP. Net 6 middleware series - conditional Middleware