【WPF开源控件库】Material Design in XAML Toolkit

最近无意间发现了一个WPF开源控件库,还是挺流行的Material Design风格的。

官网地址:http://materialdesigninxaml.net/

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

DemoApp地址:https://github.com/MaterialDesignInXAML/MaterialDesignInXamlToolkit/releases

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

记录下自己的配置过程

集成配置过程:

1.安装控件库

管理NuGet程序包:搜索MaterialDesignShowMeTheXAML,Material Design In Xaml Toolkit 需要依赖这两个包,安装好。

image
image

安装完成后,在引用中还可以看到因为依赖关系,装了另外一个包MaterialDesignColors,这个后面要用到关于色彩的。

image

2.配置App.xaml

首先,需要添加一个主题(Light或者Dark):

Light theme:

<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Light.xaml" />

Dark theme:

<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Dark.xaml" />

然后需要加载MaterialDesignTheme.Defaults.xaml这个文件,这其中包含了所有的控件样式:

<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" />

最后需要添加色彩,定义两个调色板:Primary和Accent,加入下面的代码:

<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Primary/MaterialDesignColor.COLOR_NAME.xaml" />

<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Accent/MaterialDesignColor.COLOR_NAME.xaml" />

其中将COLOR_NAME换成你想要的任意颜色。想知道有哪些颜色可以查看MaterialDesignColors 项目的 Primary 和 Accent文件夹。

那这样配置完成后,你的App.xaml文件现在应该长这样:

image

3.窗体配置

在需要使用控件的窗体、页面等文件中引入控件集名字空间

xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"

4.使用控件

打开从GitHub上下载的DemoApp,找到MaterialDesignDemo.exe文件,并运行。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容