C# WPF之Material Design自定义颜色
C# WPF之Material Design自定义颜色
阅读导航
- 本文背景
- 代码实现
- 本文参考
1. 本文背景
主要介绍使用Material Design开源控件库的自定义颜色功能

2. 代码实现
使用 .Net Core 3.1 创建名为 “CustomColorDemo” 的WPF模板项目,添加两个个Nuget库:MaterialDesignThemes、MaterialDesignColors。
MaterialDesign控件库

2.1 引入MD控件样式
文件【App.xaml】
<Application x:Class="CustomColorDemo.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:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Light.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" />
</ResourceDictionary.MergedDictionaries>
<!--PRIMARY-->
<SolidColorBrush x:Key="PrimaryHueLightBrush" Color="#349fda"/>
<SolidColorBrush x:Key="PrimaryHueLightForegroundBrush" Color="#333333"/>
<SolidColorBrush x:Key="PrimaryHueMidBrush" Color="#0288d1"/>
<SolidColorBrush x:Key="PrimaryHueMidForegroundBrush" Color="#FFFFFF"/>
<SolidColorBrush x:Key="PrimaryHueDarkBrush" Color="#015f92"/>
<SolidColorBrush x:Key="PrimaryHueDarkForegroundBrush" Color="#FFFFFF"/>
<!--ACCENT-->
<SolidColorBrush x:Key="SecondaryAccentBrush" Color="#689f38"/>
<SolidColorBrush x:Key="SecondaryAccentForegroundBrush" Color="#FFFFFF"/>
</ResourceDictionary>
</Application.Resources>
</Application>
2.2 展示界面
文件【MainWindow.xaml】代码:
<Window x:Class="CustomColorDemo.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800" WindowStartupLocation="CenterScreen">
<Grid>
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
<StackPanel Orientation="Horizontal">
<Button Style="{StaticResource MaterialDesignRaisedLightButton}" Width="90" Content="LIGHT" Margin="10"/>
<Button Style="{StaticResource MaterialDesignRaisedButton}" Width="90" Content="MID" Margin="10"/>
<Button Style="{StaticResource MaterialDesignRaisedDarkButton}" Width="90" Content="DARK" Margin="10"/>
<Button Style="{StaticResource MaterialDesignRaisedAccentButton}" Width="90" Content="ACCENT" Margin="10"/>
</StackPanel>
<GroupBox Header="USING ACCENT" materialDesign:ColorZoneAssist.Mode="Accent">
<StackPanel Orientation="Horizontal">
<DatePicker Width="100" Margin="10"/>
<CheckBox VerticalAlignment="Center" Content="Check Me" IsChecked="True" Margin="10"/>
<ToggleButton Margin="10" VerticalAlignment="Center"/>
</StackPanel>
</GroupBox>
<GroupBox Header="USING DARK" materialDesign:ColorZoneAssist.Mode="Dark">
<StackPanel Orientation="Horizontal">
<DatePicker Width="100" Margin="10"/>
<CheckBox VerticalAlignment="Center" Content="Check Me" IsChecked="False" Margin="10"/>
<ToggleButton IsChecked="True" Margin="10" VerticalAlignment="Center"/>
</StackPanel>
</GroupBox>
</StackPanel>
</Grid>
</Window>
4个按钮使用MD控件4种样式(LIGHT、MID、DARK、ACCENT),附加属性 materialDesign:ColorZoneAssist.Mode 可以修改 GroupBox 的 Header 背景色,主要看 GroupBox 内的控件,CheckBox 与 ToggleButton 的外观已经修改。
3.参考
除非注明,文章均由 Dotnet9 整理发布,欢迎转载。
转载请注明本文地址:https://dotnet9.com/7187.html
欢迎扫描下方二维码关注 Dotnet9 的微信公众号,本站会及时推送最新技术文章
C# WPF之Material Design自定义颜色的更多相关文章
- 开发Google Material Design风格的WPF程序
今天在网上看到了一个Material Design风格的WPF皮肤,看上去还是挺不错的 这个项目是开源的,感兴趣的朋友可以下载试下: https://github.com/ButchersBoy/Ma ...
- Open-source Tutorial - Material Design for WPF UI
安装 Material Design Themes 通过 NuGet 包管理器搜索自动安装 通过 NuGet 包管理器控制台手动安装 Install-Package MaterialDesignThe ...
- 在 WinForm/WPF 下制作 Google Material Design 风格程序
国内社区没有,顺手转.WinForm: https://github.com/IgnaceMaes/MaterialSkin演示:https://www.youtube.com/watch?v=A8o ...
- 直接拿来用!十大Material Design开源项目
来自:http://www.csdn.net/article/2014-11-21/2822753-material-design-libs/1 介于拟物和扁平之间的Material Design自面 ...
- 十大Material Design开源项目
介于拟物和扁平之间的Material Design自面世以来,便引起了很多人的关注与思考,就此产生的讨论也不绝于耳.本文详细介绍了在Android开发者圈子里颇受青睐的十个Material Desig ...
- [经验总结]material design效果与开发总结
首先贴一个參考过的文章,写的不错: 在低版本号android系统上实现Material design应用 以下是工作中总结出来的,列出了在<5.0的设备是怎样实现material design的 ...
- Material Design Reveal effect(揭示效果) 你可能见过但是叫不出名字的小效果
Material Design Reveal effect(揭示效果) 你可能见过但是叫不出名字的小效果 前言: 每次写之前都会来一段(废)话.{心塞...} Google Play首页两个tab背景 ...
- Material Design Animation
Material Design Animation Authentic motion 真实的运动 运动以一种优美流动的形式描述了空间关系,功能和目的. Mass and weight: 质量和重量 在 ...
- Material Design 概念,环境和基本属性
Material Design 概念,环境和基本属性 Material Design是随Android 5.0推出的一种设计概念, 涉及到了跨平台和设备的视觉,动态,交互设计等方面. 设计概念 M ...
随机推荐
- Prometheus学习笔记之教程推荐
最近学习K8S和基于容器的监控,发现了如下的教程质量不错,记录下来以备参考 K8S最佳实战(包括了K8S的Prometheus监控和EFK日志搜集) https://jimmysong.io/kube ...
- FFMPEG学习----使用SDL播放YUV数据
命令行下配置: G:\Coding\Video\SDL\proj>tree /F 文件夹 PATH 列表 卷序列号为 0FD5-0CC8 G:. │ sdl.cpp │ SDL2.dll │ S ...
- BZOJ 4556(后缀数组+主席树求前驱后继+二分||后缀数组+二分+可持久化线段树)
换markdown写了.. 题意: 给你一个1e5的字符串,1e5组询问,求\([l_1,r_1]\)的所有子串与\([l_2,r_2]\)的lcp 思路: 首先可以发现答案是具有单调性的,我们考虑二 ...
- python之字典遍历方法
字典遍历分为三种: 遍历key 遍历value 遍历key-value key遍历: >>> person={','city':'BeiJing'} >>> for ...
- java架构之路-(netty专题)netty的编解码(出入战)与粘包拆包
上次回归: 上次博客我们主要说了netty的基本使用,都是一些固定的模式去写的,我们只需要关注我们的拦截器怎么去写就可以了,然后我们用我们的基础示例,改造了一个简单的聊天室程序,可以看到内部加了一个S ...
- 【Java并发工具类】ReadWriteLock
前言 前面介绍过ReentrantLock,它实现的是一种标准的互斥锁:每次最多只有一个线程能持有ReentrantLock.这是一种强硬的加锁规则,在某些场景下会限制并发性导致不必要的抑制性能.互斥 ...
- 不用'+'完成a + b
这也是'+'底层运算原理: #include<bits/stdc++.h> using namespace std; int a,b; int main() { scanf("% ...
- idea快速创建一个类 实现一个接口
一 创建一个接口类 二 点击接口名称 按alt + ent 三 选择implement interface 选项 完美!!!!!!!
- MySQL中大数据表增加字段,增加索引实现
MySQL中大数据表增加字段,通过增加索引实现 普通的添加字段sql ALTER TABLE `table_name` ADD COLUMN `num` int(10) NOT NULL DEFAUL ...
- 如何通过adb command 完成自动SD卡升级?
如何通过adb command 完成自动SD卡升级? 原创 2014年09月09日 10:50:57 2746 通过adb 命令的方式,免去了按powerkey+volumeup进入menu sele ...
