- 新建.net8 wpf項目
- nuget添加MaterialDesignThemes引用,現在可以用5.2.1,注意:可以只有添加這個包即可,因為新nuget會自動依賴引用MaterialDesignColors和Microsoft.Xaml.Behaviors.Wpf,當然也可以添加引用進來
- 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是新的設計,更偏扁平化吧
- 每個xaml窗口中添加xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
- 上面的就已經可以正使用了,比如在button上添加樣式:Button materialDesign:ButtonAssist.CornerRadius="10" Style="{StaticResource MaterialDesignFlatLightBgButton}"
浙公網安備 33010602011771號