【发布时间】:2012-08-19 04:56:17
【问题描述】:
我需要帮助才能在 WPF 中创建带圆角的按钮。我想在上面使用渐变背景!
我需要在后面的代码中设置它,而不是在 XAML 中。会在运行时设置,不知道要创建多少个按钮。
【问题讨论】:
标签: wpf button code-behind
我需要帮助才能在 WPF 中创建带圆角的按钮。我想在上面使用渐变背景!
我需要在后面的代码中设置它,而不是在 XAML 中。会在运行时设置,不知道要创建多少个按钮。
【问题讨论】:
标签: wpf button code-behind
因为会在运行时创建,所以我不知道要创建多少个按钮。
这不是 WPF 中的正当理由,有一个叫做 data-templating 的东西。
【讨论】:
您只需要为您的按钮创建一个默认样式(在您的情况下为四舍五入)。 比如要修改Button控件
在您的主题中 (Generic.xaml)
<Style TargetType="{x:Type Button}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
// Your button style
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
然后,每次添加新按钮时,都会使用这个主题。
【讨论】: