《WPF》UI框架MaterialDesignTheme的使用

《WPF》UI框架MaterialDesignTheme的使用


文章目录

  • 《WPF》UI框架MaterialDesignTheme的使用
  • 前言
  • 一、MaterialDesignTheme是什么?
  • 二、使用步骤
    • 1.引入库
    • 1.配置资源
    • 2.控件样式
      • 2.1TextBox样式
  • 结束


前言

一边学习一边记录


一、MaterialDesignTheme是什么?

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

二、使用步骤

1.引入库

使用NuGet添加Material Design资源
《WPF》UI框架MaterialDesignTheme的使用_第1张图片

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"
		

结束

你可能感兴趣的:(wpf,ui,c#)