前言
因为业务的需求,需要用到WPF写windows桌面应用,所以想到了使用MaterialDesign,因为本人对桌面应用开发不熟悉,所以一直在踩坑,在此记录一下。
步骤一:创建新的WPF项目,引用MaterialDesign样式
这个根据网上的教程就能完成,但是也遇到一个坑
坑1:安装nuget直接下载的MaterialDesignThemes老是下载不成功,我直接到官网下下载下来了,通过导入nuget实现对MaterialDesign样式的使用。
步骤二:使用MaterialDesignInXamlToolkit-3.2.0的demo样式
坑2:去github下载完源码之后,源码编程不成功。
正常步骤:
1.进入文件夹.paket
2.在此路径中打开命令行终端。
3.使用命令 paket.exe install
下载依赖,但是这里就会出现很多问题,归根到底是连不上nuget.org官网进行资源下载。
找了很多资料之后,得到的思路是:先找出nuget.org官网的ip地址,再修改系统的hosts文件,添加对应的地址进去。步骤教程
下载成功后,才可进行解决方案的运行
一系列操作下来真的好累。。。不说了,,,开始设计UI了。。。
====================================================================
下载完记得载app.xaml中引用
<Application x:Class="AutomaticWeighingSys.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:AutomaticWeighingSys"
StartupUri="MainWindow.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>
</Application>