WPF中MaterialDesignThemes框架的使用

前言
本文主要讲如何使用MaterialDesignThemes的安装和简单使用,有什么不明白的地方可以评论区留言,一起交流学习一下

开发工具:VS2019

一、使用步骤

1.通过Nuget安装MaterialDesignThemes

①右键解决方案名称,点击管理Nuget程序包
在这里插入图片描述

②搜索MaterialDesign,点击安装,如下图
在这里插入图片描述

安装哪个版本可以自己选择,我安装使用的是4.5.0版本

点击安装之后,再点击已安装我们会发现MaterialDesignColors和MaterialDesignThemes都已经安装好

在这里插入图片描述

③在App.xml文件中的<Application.Resources> </Application.Resources>中添加资源字典,添加代码如下:

<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.Blue.xaml"/>
                <ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Accent/MaterialDesignColor.Indigo.xaml"/>
                <ResourceDictionary Source="Dictionary\DictRadioButton-2.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>

如下图:

在这里插入图片描述

添加完之后红框中的代码下面可能会出现波浪线,并报错资源找不到之类的,此时无需担心,点击启动项目或者生成一下,错误和波浪线就消失了

2.下载MaterialDesignInXamlToolkit源代码和Demo下载
简单使用下载Demo就够了,下载源码是为了某些资源访问不到时去源码里面抄代码。

github下载地址:https://github.com/MaterialDesignInXAML/MaterialDesignInXamlToolkit/releases
这里不再赘述。

二、效果展示

首先引入

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

在标签中通过Style="{StaticResource MaterialDesignRaisedButton}"进行绑定

具体代码如下:

 <Button Style="{StaticResource MaterialDesignRaisedButton}"
                       Name="btn_autoMove"  Height="44" Width="50" materialDesign:ButtonAssist.CornerRadius="300" 
                       ToolTip="MaterialDesignRaisedButton with Round Corners" Margin="20,0,0,0" Background="Blue">
 </Button>

效果如下:
在这里插入图片描述

  • 6
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值