【发布时间】:2016-09-03 08:01:32
【问题描述】:
我尝试为启用或禁用 WPF 按钮设置通用样式:
<Style x:Name="btnStyle" x:Key="btnStyle" TargetType="{x:Type Button}">
<Setter Property="Foreground" Value="#FFFFFFFF"/>
<Setter Property="BorderBrush" Value="#FFCFFFFF"/>
<Style.Triggers>
<Trigger Property="IsEnabled" Value="True">
<Setter Property="Style" Value="{DynamicResource btnStyle}" />
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Style" Value="{DynamicResource btnStyle}" />
</Trigger>
</Style.Triggers>
</Style>
还有我的按钮:
<Button Style="{StaticResource btnStyle}"/>
这会在运行时产生以下异常。
"Style object is not allowed to affect the Style property of the object to which it applies."
如何将这种通用样式应用于按钮的两种状态?我可以在不使用样式覆盖按钮模板的情况下做到这一点吗?
【问题讨论】:
标签: .net wpf xaml exception button