×

WPF中MaterialDesignThemes前端框架的使用(超详细图解步骤)

Kalet Kalet 发表于2023-02-27 12:33:25 浏览393 评论0

抢沙发发表评论

转自:https://blog.csdn.net/Zzu_zzx/article/details/126303547


前言

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

开发工具:VS2019

一、使用步骤

1.通过Nuget安装MaterialDesignThemes
①右键解决方案名称,点击管理Nuget程序包



②搜索MaterialDesign,点击安装,如下图

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



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



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

    <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Light.xaml">
                </ResourceDictionary>
                <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml">
                </ResourceDictionary>
                <ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Primary/MaterialDesignColor.Blue.xaml">
                </ResourceDictionary>
                <ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Accent/MaterialDesignColor.Blue.xaml">
                </ResourceDictionary>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
如下图:

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

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

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

找到自己需要的版本(此文章使用为V3.1.0版本)



下载完解压打开Demo中的MaterialDesignDemo.exe

 

如下:



然后找到自己想要的效果,复制代码添加到wpf页面中



将复制的圆角按钮代码添加到wpf页面中,如下图,便可看到使用成功:

同时需要将下面一句代码添加到图中提示位置:

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


群贤毕至

访客