当前位置:   article > 正文

WPF 使用 MaterialDesign 控件库_materialdesign教程 wpf

materialdesign教程 wpf

连接

官网:链接: http://materialdesigninxaml.net.

GitHub源码及DemoApp地址:https://github.com/MaterialDesignInXAML/MaterialDesignInXamlToolkit/releases.

使用

1.安装

在NuGet安装MaterialDesignThemes
在这里插入图片描述

2.添加配置

在App.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 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>
 </Application.Resources>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

3.引入命名空间

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

<Window x:Class="HostComputer.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:HostComputer"
        
        xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
        
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

4.使用控件

1) 打开下载好的DemoApp选择要使用的控件。
在这里插入图片描述
2) 复制到程序中
在这里插入图片描述
3) 运行效果
添加成功
在这里插入图片描述

5.修改主题风格

在App.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 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>
         <SolidColorBrush x:Key="PrimaryHueLightBrush" Color="#ffc947"/>
         <SolidColorBrush x:Key="PrimaryHueLightForegroundBrush" Color="#ffffff"/>
         <SolidColorBrush x:Key="PrimaryHueMidBrush" Color="#ff9800"/>
         <SolidColorBrush x:Key="PrimaryHueMidForegroundBrush" Color="#ffffff"/>
         <SolidColorBrush x:Key="PrimaryHueDarkBrush" Color="#c66900"/>
         <SolidColorBrush x:Key="PrimaryHueDarkForegroundBrush" Color="#ffffff"/>
     </ResourceDictionary>
 </Application.Resources>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

效果
在这里插入图片描述

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/繁依Fanyi0/article/detail/97845
推荐阅读
相关标签
  

闽ICP备14008679号