WPF 擴展MaterialDesignTheme主題


項目中用到了MaterialDesignTheme,他只有兩種主題,light和dark。

查看源碼,將他dark主題copy到我們項目中

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

    <Color x:Key="MaterialDesignValidationErrorColor">#f44336</Color>
    <SolidColorBrush x:Key="MaterialDesignValidationErrorBrush" Color="{StaticResource MaterialDesignValidationErrorColor}"/>

    <SolidColorBrush x:Key="MaterialDesignBackground" Color="#FF000000" po:Freeze="True" />
    <SolidColorBrush x:Key="MaterialDesignPaper" Color="#FF303030" po:Freeze="True" />
    <SolidColorBrush x:Key="MaterialDesignCardBackground" Color="#FF424242" po:Freeze="True" />
    <SolidColorBrush x:Key="MaterialDesignToolBarBackground" Color="#FF212121" po:Freeze="True" />
    <SolidColorBrush x:Key="MaterialDesignBody" Color="#DDFFFFFF" po:Freeze="True" />
    <SolidColorBrush x:Key="MaterialDesignBodyLight" Color="#89FFFFFF" po:Freeze="True" />
    <SolidColorBrush x:Key="MaterialDesignColumnHeader" Color="#BCFFFFFF" po:Freeze="True" />

    <SolidColorBrush x:Key="CommonBodyForeground" Color="White"/>
    <SolidColorBrush x:Key="CommonBorderBursh" Color="#FF4B9598" />
    <!-- 74% -->

    <SolidColorBrush x:Key="MaterialDesignCheckBoxOff" Color="#89FFFFFF" po:Freeze="True" />
    <SolidColorBrush x:Key="MaterialDesignCheckBoxDisabled" Color="#FF647076" po:Freeze="True" />

    <SolidColorBrush x:Key="MaterialDesignTextBoxBorder" Color="#89FFFFFF" po:Freeze="True" />
    <SolidColorBrush x:Key="MaterialDesignDivider" Color="#1FFFFFFF" po:Freeze="True" />
    <!-- 12% -->
    <SolidColorBrush x:Key="MaterialDesignSelection" Color="#757575" po:Freeze="True" />

    <SolidColorBrush x:Key="MaterialDesignToolForeground" Color="#616161" po:Freeze="true" />
    <SolidColorBrush x:Key="MaterialDesignToolBackground" Color="#e0e0e0" po:Freeze="true" />

    <SolidColorBrush x:Key="MaterialDesignFlatButtonClick" Color="#19757575" po:Freeze="True" />
    <!-- 25% -->
    <SolidColorBrush x:Key="MaterialDesignFlatButtonRipple" Color="#FFB6B6B6" po:Freeze="True" />

    <SolidColorBrush x:Key="MaterialDesignToolTipBackground" Color="#eeeeee" po:Freeze="True" />
    <SolidColorBrush x:Key="MaterialDesignChipBackground" Color="#FF2E3C43" po:Freeze="True" />
    <SolidColorBrush x:Key="MaterialDesignSnackbarBackground" Color="#FFCDCDCD" po:Freeze="True" />
    <SolidColorBrush x:Key="MaterialDesignSnackbarMouseOver" Color="#FFB9B9BD" po:Freeze="True" />
    <SolidColorBrush x:Key="MaterialDesignSnackbarRipple" Color="#FF494949" po:Freeze="True" />

    <SolidColorBrush x:Key="MaterialDesignTextFieldBoxBackground" Color="#1AFFFFFF" po:Freeze="True" />
    <!-- 10% white -->
    <SolidColorBrush x:Key="MaterialDesignTextFieldBoxHoverBackground" Color="#1FFFFFFF" po:Freeze="True" />
    <!-- 12% white -->
    <SolidColorBrush x:Key="MaterialDesignTextFieldBoxDisabledBackground" Color="#0DFFFFFF" po:Freeze="True" />
    <!-- 5% white -->
    <SolidColorBrush x:Key="MaterialDesignTextAreaBorder" Color="#BCFFFFFF" po:Freeze="True" />
    <!-- 74% white -->
    <SolidColorBrush x:Key="MaterialDesignTextAreaInactiveBorder" Color="#29FFFFFF" po:Freeze="True" />
    <!-- 41% white (= 74% * 56%) -->

    <SolidColorBrush x:Key="MaterialDesignDataGridRowHoverBackground" Color="#14FFFFFF" po:Freeze="True" />
    <!-- 8% white -->
</ResourceDictionary>

 

 復制這個Theme.Dark.xaml文件,重命名為Theme.DarkBule.xaml,修改里面的顏色

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

    <Color x:Key="MaterialDesignValidationErrorColor">#f44336</Color>
    <SolidColorBrush x:Key="MaterialDesignValidationErrorBrush" Color="{StaticResource MaterialDesignValidationErrorColor}"/>

    <SolidColorBrush x:Key="PrimaryHueDarkBrush" Color="#FF252525"/>
    <SolidColorBrush x:Key="PrimaryHueDarkForegroundBrush" Color="White"/>
    <SolidColorBrush x:Key="MaterialDesignBody" Color="#FF252525"/>
    <SolidColorBrush x:Key="MaterialDesignPaper" Color="#FF55AAAD"/>
    <SolidColorBrush x:Key="CommonBodyForeground" Color="White"/>
    <SolidColorBrush x:Key="CommonBorderBursh" Color="#FF4B9598" />
    <SolidColorBrush x:Key="MaterialDesignColumnHeader" Color="#FF252525"/>
    <SolidColorBrush x:Key="MaterialDesignDivider" Color="#FF4B9598" />
    <SolidColorBrush x:Key="MaterialDesignSelection" Color="#FF4B9598"   />

    <SolidColorBrush x:Key="MaterialDesignBackground" Color="#FF000000" po:Freeze="True" />
    <SolidColorBrush x:Key="MaterialDesignCardBackground" Color="#FF424242" po:Freeze="True" />
    <SolidColorBrush x:Key="MaterialDesignToolBarBackground" Color="#FF212121" po:Freeze="True" />
    <SolidColorBrush x:Key="MaterialDesignBodyLight" Color="#89FFFFFF" po:Freeze="True" />

    <SolidColorBrush x:Key="MaterialDesignCheckBoxOff" Color="#89FFFFFF" po:Freeze="True" />
    <SolidColorBrush x:Key="MaterialDesignCheckBoxDisabled" Color="#FF647076" po:Freeze="True" />

    <SolidColorBrush x:Key="MaterialDesignTextBoxBorder" Color="#89FFFFFF" po:Freeze="True" />

    <SolidColorBrush x:Key="MaterialDesignToolForeground" Color="#616161" po:Freeze="true" />
    <SolidColorBrush x:Key="MaterialDesignToolBackground" Color="#e0e0e0" po:Freeze="true" />

    <SolidColorBrush x:Key="MaterialDesignFlatButtonClick" Color="#19757575" po:Freeze="True" /> <!-- 25% -->
    <SolidColorBrush x:Key="MaterialDesignFlatButtonRipple" Color="#FFB6B6B6" po:Freeze="True" />

    <SolidColorBrush x:Key="MaterialDesignToolTipBackground" Color="#eeeeee" po:Freeze="True" />
    <SolidColorBrush x:Key="MaterialDesignChipBackground" Color="#FF2E3C43" po:Freeze="True" />
    <SolidColorBrush x:Key="MaterialDesignSnackbarBackground" Color="#FFCDCDCD" po:Freeze="True" />
    <SolidColorBrush x:Key="MaterialDesignSnackbarMouseOver" Color="#FFB9B9BD" po:Freeze="True" />
    <SolidColorBrush x:Key="MaterialDesignSnackbarRipple" Color="#FF494949" po:Freeze="True" />

    <SolidColorBrush x:Key="MaterialDesignTextFieldBoxBackground" Color="#1AFFFFFF" po:Freeze="True" /> <!-- 10% white -->
    <SolidColorBrush x:Key="MaterialDesignTextFieldBoxHoverBackground" Color="#1FFFFFFF" po:Freeze="True" /> <!-- 12% white -->
    <SolidColorBrush x:Key="MaterialDesignTextFieldBoxDisabledBackground" Color="#0DFFFFFF" po:Freeze="True" /> <!-- 5% white -->
    <SolidColorBrush x:Key="MaterialDesignTextAreaBorder" Color="#BCFFFFFF" po:Freeze="True" /> <!-- 74% white -->
    <SolidColorBrush x:Key="MaterialDesignTextAreaInactiveBorder" Color="#29FFFFFF" po:Freeze="True" /> <!-- 41% white (= 74% * 56%) -->

    <SolidColorBrush x:Key="MaterialDesignDataGridRowHoverBackground" Color="#14FFFFFF" po:Freeze="True" /> <!-- 8% white -->
</ResourceDictionary>

用法:

 

 

 

 

如圖,把他官方的,調用主題的那行注釋掉,添加一行source指定到我們擴展的主題文件。

 

 

 

 配色忽略,沒有美工....


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM