ARTICLE DETAIL

资讯详情

深耕网站建设、视觉设计与SEO优化的一线实战洞察。

在wpf .net 8项目中使用materialDesign 4 以上版本的的注意事项

在wpf .net 8项目中使用materialDesign 4 以上版本的的注意事项
  1. 新建.net8 wpf项目
  2. nuget添加MaterialDesignThemes引用,现在可以用5.2.1,注意:可以只有添加这个包即可,因为新nuget会自动依赖引用MaterialDesignColors和Microsoft.Xaml.Behaviors.Wpf,当然也可以添加引用进来
  3. app.xaml:

    <Application x:Class="WpfApp1.App"

    xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:WpfApp1"
    StartupUri="MainWindow.xaml">

    <Application.Resources>
    <ResourceDictionary>
    <ResourceDictionary.MergedDictionaries>
    <materialDesign:CustomColorTheme
    BaseTheme="Light"
    PrimaryColor="BlueViolet"
    SecondaryColor="DarkGreen"/>
    <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesign2.Defaults.xaml" />
    </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
    </Application.Resources>

    </Application>  注意,上面可以用MaterialDesign2和MaterialDesign2,官方解释是2偏向以前设计规范,圆角小,阴影深,3是新的设计,更偏扁平化吧

  4. 每个xaml窗口中添加xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
  5. 上面的就已经可以正使用了,比如在button上添加样式:Button materialDesign:ButtonAssist.CornerRadius="10" Style="{StaticResource MaterialDesignFlatLightBgButton}"
返回列表