1. 添加 NuGet 包

  在解决方案管理器视图中的目标项目上右键  -> 管理 NuGet 程序包;

  添加 MaterialDesignThemes 包,如下图所示:

  

     

 

2. 配置 App.xaml

  App.xaml 应该是类似这样的:

  更改此处来更改主题和颜色 BaseTheme="Light" PrimaryColor="Aqua" SecondaryColor="DarkGreen"

<Application x:Class="Example.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
             StartupUri="MainWindow.xaml">
<Application.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <materialDesign:BundledTheme BaseTheme="Light" PrimaryColor="Indigo" SecondaryColor="Lime" /> <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" /> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> </Application.Resources>
</Application>

 

3. 配置 Window

  向窗口的开始标签添加一些参数。为了获得完整的材质设计体验,你应该这样设置字体:

<Window [...]
        xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
        TextElement.Foreground="{DynamicResource MaterialDesignBody}"
        Background="{DynamicResource MaterialDesignPaper}"
        TextElement.FontWeight="Medium"
        TextElement.FontSize="14"
        FontFamily="{materialDesign:MaterialDesignFont}"
        [...] >

 

4. 开始使用

  打开从 GitHub 上下载的 MaterialDesignDemo.exe 查看控件效果和代码。

  Demo 下载地址:https://github.com/ButchersBoy/MaterialDesignInXamlToolkit/releases

  GitHub 地址:https://github.com/MaterialDesignInXAML/MaterialDesignInXamlToolkit

 

5. 参考

  官方入门指导:https://github.com/MaterialDesignInXAML/MaterialDesignInXamlToolkit/wiki/Getting-Started

 

posted on 2020-06-17 16:50  青叶煮酒  阅读(10736)  评论(0编辑  收藏  举报