一、自定义按钮的默认样式(静态资源)
1、创建资源词典
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style x:Key="MyButton" TargetType="{x:Type Button}">
<Setter Property="Background" Value="Red" />
</Style>
</ResourceDictionary>
2、引入资源文件(App.xaml)
<Application x:Class="WpfApp1.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
StartupUri="MainWindow.xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/Dictionary1.xaml" />
</ResourceDictionary.MergedDictionaries>
<Style BasedOn="{StaticResource MyButton}" TargetType="Button"></Style>
</ResourceDictionary>
</Application.Resources>
</Application>
3、创建Button控件
二、自定义样式(动态资源)
1、添加样式
<SolidColorBrush x:Key="Primary" Color="Orange"/>
2、修改控件样式