尝试这个:
<Border x:Name="border">
<Border.Style>
<Style TargetType="{x:Type Border}">
<Style.Triggers>
<EventTrigger RoutedEvent="MouseDown">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard>
<ObjectAnimationUsingKeyFrames Duration="0"
Storyboard.TargetProperty="(Border.IsEnabled)">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<sys:Boolean>False</sys:Boolean>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
</Style.Triggers>
</Style>
</Border.Style>
</Border>
我们使用 aStoryboard
来解决无法Setter
直接设置 a 的问题,并让 Animation 瞬间产生即时效果。
更新:
下载链接:这里
另一个更新(在 上显示不同的禁用状态Border
)
<Border x:Name="border"
BorderThickness="5">
<Border.Style>
<Style TargetType="{x:Type Border}">
<Setter Property="Background"
Value="BurlyWood" />
<Setter Property="BorderBrush"
Value="Blue" />
<Style.Triggers>
<EventTrigger RoutedEvent="MouseDown">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard>
<ObjectAnimationUsingKeyFrames Duration="0"
Storyboard.TargetProperty="(Border.IsEnabled)">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<sys:Boolean>False</sys:Boolean>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
<Trigger Property="IsEnabled"
Value="False">
<Setter Property="Background"
Value="Gray" />
<Setter Property="BorderBrush"
Value="DarkGray" />
</Trigger>
</Style.Triggers>
</Style>
</Border.Style>
<Button Margin="100"
Content="Some Button" />
</Border>