最近無意間發(fā)現(xiàn)了一個(gè)WPF開源控件庫,還是挺流行的Material Design風(fēng)格的。
官網(wǎng)地址:http://materialdesigninxaml.net/
GitHUb地址:https://github.com/MaterialDesignInXAML/MaterialDesignInXamlToolkit
DemoApp地址:https://github.com/MaterialDesignInXAML/MaterialDesignInXamlToolkit/releases
官方入門指導(dǎo):https://github.com/MaterialDesignInXAML/MaterialDesignInXamlToolkit/wiki/Getting-Started
記錄下自己的配置過程
集成配置過程:
1.安裝控件庫
管理NuGet程序包:搜索MaterialDesign 和ShowMeTheXAML,Material Design In Xaml Toolkit 需要依賴這兩個(gè)包,安裝好。


安裝完成后,在引用中還可以看到因?yàn)橐蕾囮P(guān)系,裝了另外一個(gè)包MaterialDesignColors,這個(gè)后面要用到關(guān)于色彩的。

2.配置App.xaml
首先,需要添加一個(gè)主題(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這個(gè)文件,這其中包含了所有的控件樣式:
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" />
最后需要添加色彩,定義兩個(gè)調(diào)色板: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 項(xiàng)目的 Primary 和 Accent文件夾。
那這樣配置完成后,你的App.xaml文件現(xiàn)在應(yīng)該長這樣:

3.窗體配置
在需要使用控件的窗體、頁面等文件中引入控件集名字空間
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
4.使用控件
打開從GitHub上下載的DemoApp,找到MaterialDesignDemo.exe文件,并運(yùn)行。