1.资源字典定义:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style TargetType="Button" x:Key="GroupBoxButton">
<Setter Property="Width" Value="72"/>
<Setter Property="Height" Value="30"/>
<Setter Property="Margin" Value="5"/>
<Setter Property="Background" Value="Black"/>
</Style>
</ResourceDictionary>
2.后台代码
Button b = new Button();
b.Style = FindResource("GroupBoxButton") as Style;