我在堆栈面板中有一个按钮
<StackPanel>
<Button x:Name="CreateBtn" Content="Create" Style="{StaticResource PopUpButton}" Width="120" HorizontalAlignment="Right" Margin="0 60 30 0" Command="{Binding SaveCardTypeCommand}" />
</StackPanel>
使用文件中的样式
<Style x:Key="PopUpButton" TargetType="Button">
<Setter Property="Foreground" Value="#1172b7"/>
<Setter Property="BorderBrush" Value="#1172b7"/>
<Setter Property="BorderThickness" Value="3"/>
</Style>
我需要在禁用按钮时将内容和边框刷的颜色更改为红色
我该怎么做?
祝你好运
答案 0 :(得分:1)
使用表达式混合编辑按钮的默认模板并自定义视觉状态。您可以为每个视觉状态定义动画。
<VisualState x:Name="Disabled">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="BorderBrush" Storyboard.TargetName="Border">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<SolidColorBrush Color="Red"/>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="ContentPresenter">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<SolidColorBrush Color="Red"/>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>