《WPF》UI框架MaterialDesignTheme的使用

发布于:2022-12-05 ⋅ 阅读:(2196) ⋅ 点赞:(2)

《WPF》UI框架MaterialDesignTheme的使用



前言

一边学习一边记录


一、MaterialDesignTheme是什么?

MaterialDesignTheme是由Google推出的开源免费的UI框架。

二、使用步骤

1.引入库

使用NuGet添加Material Design资源
在这里插入图片描述

1.配置资源

在App.xaml中需要编写

代码如下:

    <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 Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Primary/MaterialDesignColor.DeepPurple.xaml" />
                <ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Accent/MaterialDesignColor.Lime.xaml" />
            </ResourceDictionary.MergedDictionaries>
	</ResourceDictionary>

也可以在里面添加主题颜色

   			<SolidColorBrush x:Key="PrimaryHueLightBrush" Color="#BBB" />
            <SolidColorBrush x:Key="PrimaryHueLightForegroundBrush" Color="#BBB" />
            <SolidColorBrush x:Key="PrimaryHueMidBrush" Color="#004098" />
            <SolidColorBrush x:Key="PrimaryHueMidForegroundBrush" Color="White" />
            <SolidColorBrush x:Key="PrimaryHueDarkBrush" Color="White" />
            <SolidColorBrush x:Key="PrimaryHueDarkForegroundBrush" Color="#004098" />
            <SolidColorBrush x:Key="SecondaryAccentBrush" Color="#004098" />
            <SolidColorBrush x:Key="SecondaryAccentForegroundBrush" Color="Yellow" />
            <SolidColorBrush x:Key="PrimaryLightBrush" Color="Red" />
            <SolidColorBrush x:Key="PrimaryLightForegroundBrush" Color="Green" />

2.控件样式

需要在窗体的头部添加 xmlns:materialDesign=“http://materialdesigninxaml.net/winfx/xaml/themes”

2.1TextBox样式

		//默认提示文字
		materialDesign:HintAssist.Hint="输入查询条件" 
		//默认提示文字是否会悬浮在文本框上
		materialDesign:HintAssist.IsFloating="False"
		

结束