当前位置:   article > 正文

C#WPF 配置使用MaterialDesign_wpf material design

wpf material design

一、安装工具包

1、打开程序包管理器控制台

视图 > 其他窗口 > 程序包管理器控制台

 2、安装程序包

打开管理NuGet程序包,搜索MaterialDesignThemes,进行安装

 打开  视图 .>  其他窗口  >  程序包管理控制台

 在程序包管理控制台中输入:

  1. PM> Install-Package MaterialDesignThemes
  2. PM> Install-Package ShowMeTheXAML.MSBuild

二、修改配置App.xaml

App.xaml文件

  1. <Application x:Class="WpfApp3.App"
  2. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  4. xmlns:local="clr-namespace:WpfApp3"
  5. StartupUri="MainWindow.xaml">
  6. <Application.Resources>
  7. <ResourceDictionary>
  8. <ResourceDictionary.MergedDictionaries>
  9. <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Light.xaml" />
  10. <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" />
  11. <ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Primary/MaterialDesignColor.DeepPurple.xaml" />
  12. <ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Accent/MaterialDesignColor.Lime.xaml" />
  13. </ResourceDictionary.MergedDictionaries>
  14. </ResourceDictionary>
  15. </Application.Resources>
  16. </Application>

三、在WPF窗口Xaml中引入命名控件

在MainWindow.xaml中的Window标签中添加

  1. <Window [...]
  2. xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
  3. [...] >

四、使用MaterialDesign控件

  1. <Grid>
  2. <materialDesign:PopupBox Closed="PopupBox_OnClosed"
  3. IsEnabled="{Binding DataContext.ControlsEnabled, RelativeSource={RelativeSource FindAncestor, AncestorType=Window}}"
  4. Opened="PopupBox_OnOpened"
  5. PlacementMode="BottomAndAlignCentres"
  6. Style="{StaticResource MaterialDesignMultiFloatingActionPopupBox}"
  7. ToolTip="PopupBox, Style MaterialDesignMultiFloatingActionPopupBox"
  8. ToolTipService.Placement="Right">
  9. <StackPanel>
  10. <Button
  11. Content="1"
  12. Opacity="0.5"
  13. ToolTip="One with custom opacity" />
  14. <Button
  15. Content="2"
  16. ToolTip="Two" />
  17. <Button
  18. Content="3"
  19. ToolTip="Three" />
  20. </StackPanel>
  21. </materialDesign:PopupBox>
  22. </Grid>

此时代码报错,因为缺少一些引用。上述代码中使用了PopupBox控件,继续在App.xaml中添加

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

引用的程序集不全,有一些控件需要单独在App.xaml中引用一下程序集。

五、效果

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/IT小白/article/detail/97872
推荐阅读
相关标签
  

闽ICP备14008679号