惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
T
Threatpost
Latest news
Latest news
N
News | PayPal Newsroom
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Help Net Security
Help Net Security
D
Darknet – Hacking Tools, Hacker News & Cyber Security
AI
AI
Simon Willison's Weblog
Simon Willison's Weblog
TaoSecurity Blog
TaoSecurity Blog
The Last Watchdog
The Last Watchdog
L
LINUX DO - 热门话题
Google DeepMind News
Google DeepMind News
T
Threat Research - Cisco Blogs
O
OpenAI News
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
T
The Exploit Database - CXSecurity.com
NISL@THU
NISL@THU
Application and Cybersecurity Blog
Application and Cybersecurity Blog
S
Securelist
小众软件
小众软件
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Martin Fowler
Martin Fowler
S
SegmentFault 最新的问题
Cisco Talos Blog
Cisco Talos Blog
云风的 BLOG
云风的 BLOG
AWS News Blog
AWS News Blog
GbyAI
GbyAI
N
News and Events Feed by Topic
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
美团技术团队
Engineering at Meta
Engineering at Meta
A
About on SuperTechFans
博客园 - 三生石上(FineUI控件)
S
Schneier on Security
博客园 - 聂微东
V2EX - 技术
V2EX - 技术
T
Troy Hunt's Blog
SecWiki News
SecWiki News
S
Secure Thoughts
B
Blog RSS Feed
Hugging Face - Blog
Hugging Face - Blog
WordPress大学
WordPress大学
腾讯CDC
H
Heimdal Security Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Apple Machine Learning Research
Apple Machine Learning Research
月光博客
月光博客
www.infosecurity-magazine.com
www.infosecurity-magazine.com
P
Privacy International News Feed

博客园 - fenix

IISExpress 开放局域网访问 sql窗口函数 Sql分页语句 常用SQL 数据库导出结构的sql WebAPI post 跨域调用及坑 单进程运行 iis7 添加Mime sudoku Geometric paths,mini language Accessing WMF metadata with C# 标点符号 摘抄 temp C# deep copy 数独 简单对称加密 ICommand ASP.NET 4 Child Applications Fail to Start When Under ASP.NET 2.0 or ASP.NET 3.5 Applications
MahApps.Metro样式
fenix · 2014-09-11 · via 博客园 - fenix

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.

<Application x:Class="MahAppsMetroThemesSample.App"
         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>
                <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
                <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
                <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colors.xaml" />

                <!-- accent resource -->
                <!-- change "Cobalt" to the accent color you want -->

                <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/Cobalt.xaml" />

                <!-- theme resource -->
                <!-- change "BaseLight" to the theme you want -->
                <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseLight.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
</Application>

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.

<Controls:MetroWindow.Resources>
    <ResourceDictionary>
       <ResourceDictionary.MergedDictionaries>
            <!-- this window should be blue -->
            <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/Blue.xaml" />
            <!-- and should use the light theme -->
            <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseLight.xaml" />
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Controls:MetroWindow.Resources>

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.

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

    <!--ACCENT COLORS-->
    <Color x:Key="HighlightColor">#FF9F0055</Color>

    <!--80%-->
    <Color x:Key="AccentColor">#CCD80073</Color>
    <!--60%-->
    <Color x:Key="AccentColor2">#99D80073</Color>
    <!--40%-->
    <Color x:Key="AccentColor3">#66D80073</Color>
    <!--20%-->
    <Color x:Key="AccentColor4">#33D80073</Color>

    <!-- re-set brushes too -->
    <SolidColorBrush x:Key="HighlightBrush" Color="{StaticResource HighlightColor}" />
    <SolidColorBrush x:Key="AccentColorBrush" Color="{StaticResource AccentColor}"/>
    <SolidColorBrush x:Key="AccentColorBrush2" Color="{StaticResource AccentColor2}"/>
    <SolidColorBrush x:Key="AccentColorBrush3" Color="{StaticResource AccentColor3}"/>
    <SolidColorBrush x:Key="AccentColorBrush4" Color="{StaticResource AccentColor4}"/>

    <SolidColorBrush x:Key="WindowTitleColorBrush" Color="{StaticResource AccentColor}" />

    <SolidColorBrush x:Key="AccentSelectedColorBrush" Color="White" />

    <LinearGradientBrush x:Key="ProgressBrush" EndPoint="0.001,0.5" StartPoint="1.002,0.5">
        <GradientStop Color="{StaticResource HighlightColor}" Offset="0" />
        <GradientStop Color="{StaticResource AccentColor3}" Offset="1" />
    </LinearGradientBrush>

    <SolidColorBrush x:Key="CheckmarkFill" Color="{StaticResource AccentColor}" />
    <SolidColorBrush x:Key="RightArrowFill" Color="{StaticResource AccentColor}" />

    <Color x:Key="IdealForegroundColor">White</Color>
    <SolidColorBrush x:Key="IdealForegroundColorBrush" Color="{StaticResource IdealForegroundColor}"/>

</ResourceDictionary>

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.