博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
MahApps.Metro样式
阅读量:5008 次
发布时间:2019-06-12

本文共 3483 字,大约阅读时间需要 11 分钟。

http://mahapps.com/guides/styles.html

 

Styles

Table of Contents

Overview

This guide will introduce you to the many accents and themes that MahApps.Metro has and how to create your own.

All of MahApps.Metro's accents and themes are contained within separate resource dictionaries (Make sure that all file names are spelled correct. They are Case Sensitive!).

How to change the current theme

You can choose between these available accents:

"Red", "Green", "Blue", "Purple", "Orange", "Lime", "Emerald", "Teal", "Cyan", "Cobalt", "Indigo", "Violet", "Pink", "Magenta", "Crimson", "Amber", "Yellow", "Brown", "Olive", "Steel", "Mauve", "Taupe", "Sienna"

and these themes:

"BaseLight", "BaseDark"

via App.xaml

The fastest way is to specify the accent and theme resource in App.xaml.

Cobalt and BaseLight theme.

via ThemeManager

MahApps.Metro has a ThemeManager method that lets you change the accent and theme using the code-behind file. It can be done in 2 lines, like so:

public partial class App : Application { protected override void OnStartup (StartupEventArgs e) { // get the theme from the current application var theme = ThemeManager.DetectAppStyle(Application.Current); // now set the Green accent and dark theme ThemeManager.ChangeAppStyle(Application.Current, ThemeManager.GetAccent("Green"), ThemeManager.GetAppTheme("BaseDark")); base.OnStartup(e); } }

On a Window different to your Application's MainPage

With MahApps.Metro you can have a different accent and theme for a MetroWindow. The main window or any other MetroWindow will keep the specified accent and theme in the App.xaml.

You can also do this with the ThemeManager, like so:

public partial class AccentStyleWindow : MetroWindow { public void ChangeAppStyle() { // get the theme from the window var theme = ThemeManager.DetectAppStyle(this); // now set the Red accent and dark theme ThemeManager.ChangeAppStyle(this, ThemeManager.GetAccent("Red"), ThemeManager.GetAppTheme("BaseDark")); } }

Creating Custom Accents and Themes

Another nice feature of MahApps.Metro ThemeManager is to use custom created accents and themes or use a dynamically created accent and theme.

#FF9F0055
#CCD80073
#99D80073
#66D80073
#33D80073
White

In order to use this custom accent, you need to add it to the ThemeManager first.

public partial class App : Application { protected override void OnStartup(StartupEventArgs e) { // add custom accent and theme resource dictionaries ThemeManager.AddAccent("CustomAccent1", new Uri("pack://application:,,,/MahAppsMetroThemesSample;component/CustomAccents/CustomAccent1.xaml")); // get the theme from the current application var theme = ThemeManager.DetectAppStyle(Application.Current); // now use the custom accent ThemeManager.ChangeAppStyle(Application.Current, ThemeManager.GetAccent("CustomAccent1"), theme.Item1); base.OnStartup(e); } }

It is also possible to create an accent resource dictionary dynamically by using a specific color.

转载于:https://www.cnblogs.com/fenix/p/4494471.html

你可能感兴趣的文章
JSON.parse()和JSON.stringify()
查看>>
.net 常用正则表达式
查看>>
Java泛型中的标记符含义:
查看>>
初遇GitHub
查看>>
[C# 网络编程系列]专题八:P2P编程
查看>>
Jsの练习-数组常用方法 -forEach()
查看>>
动态绑定treeview的方法
查看>>
jvm参数
查看>>
3-1 案例环境初始化
查看>>
读《构建之法》第四章和十七章有感
查看>>
01背包
查看>>
开发一个12306网站要多少钱?技术分析12306合格还是不合格
查看>>
Selenium 入门到精通系列:六
查看>>
HTTP与TCP的区别和联系
查看>>
android 实现2张图片层叠效果
查看>>
我个人所有的独立博客wordpress都被挂马
查看>>
html5——动画案例(时钟)
查看>>
调用Android系统“应用程序信息(Application Info)”界面
查看>>
ios中用drawRect方法绘图的时候设置颜色
查看>>
数据库中的外键和主键理解
查看>>