我正在制作自定义按钮样式,我设置颜色但是:
<Style TargetType="Button" x:Key="ButtonStyle">
<Setter Property="Background">
<Setter.Value>
<SolidColorBrush Color="#0000FF" />
</Setter.Value>
</Setter>
<Setter Property="Foreground">
<Setter.Value>
<SolidColorBrush Color="White" />
</Setter.Value>
</Setter>
<Setter Property="BorderBrush">
<Setter.Value>
<SolidColorBrush Color="#00FF00" />
</Setter.Value>
</Setter>
</Style>
但是如何设置禁用(IsEnabled = false)颜色?
答案 0 :(得分:1)
如果您要更改那么多东西,您应该继续进行并在实际的Template级别进行操作,但如果您只是寻找那个刷子,您可以在字典中更改它或只需公开资源,就可以在任何地方覆盖它;
<SolidColorBrush x:Key="ButtonDisabledBackgroundThemeBrush" Color="YourColor" />
<Style TargetType="Button" x:Key="ButtonStyle">
<Setter Property="Background" Value="#0000FF" />
<Setter Property="Foreground" Value="White" />
<Setter Property="BorderBrush" Value="#00FF00" />
</Style>
希望这会有所帮助,欢呼
答案 1 :(得分:0)
在您的按钮样式中添加Common visual状态的视觉状态,例如this =&gt; 在这里,我将背景按钮proterty设置为红色。
<VisualState x:Name="Disabled">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="ContentContainer">
<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PhoneDisabledBrush}"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="BorderBrush" Storyboard.TargetName="ButtonBackground">
<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PhoneDisabledBrush}"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="ButtonBackground">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<SolidColorBrush Color="#FFF01919"/>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>