我的按钮中有样式资源以使其圆润,并且我想使用 c#(后面的代码)创建它,我该怎么做?
<Button.Resources>
<Style TargetType="Border">
<Setter Property="CornerRadius" Value="5"/>
</Style>
</Button.Resources>
创建Style
:
Style style = new Style() { TargetType = typeof(Border) };
style.Setters.Add(new Setter() { Property = Border.CornerRadiusProperty, Value = new CornerRadius(5) });
style.Seal();
将其添加到Button
:
button.Resources.Add(typeof(Border), style);
XAML:
<Button x:Name="button" Content="..." />