我有一个按钮。当它被按下时,按钮颜色应该改变。颜色是根据特定条件选择的(例如:Ok-Grey,error-Red)。这是一个简单的任务,但我无法解决它:(。我已经尝试过。我在单击按钮之前定义了术语并将其存储在属性标签(此按钮)中。我没有为普通按钮工作。我覆盖模板按钮:
<Style x:Key="SimpleButton" TargetType="{x:Type Button}">
<Setter Property="SnapsToDevicePixels" Value="true" />
<Setter Property="OverridesDefaultStyle" Value="true" />
<Setter Property="MinHeight" Value="23" />
<Setter Property="MinWidth" Value="75" />
<Setter Property="Tag" Value="1" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Border x:Name="Border"
Background="#C0C0C0"
BorderBrush="#404040"
BorderThickness="1"
CornerRadius="2">
<ContentPresenter Margin="0,6,27,6"
HorizontalAlignment="Right"
VerticalAlignment="Center"
RecognizesAccessKey="True" />
</Border>
<ControlTemplate.Triggers>
<!-- !!!!! -->
<Trigger Property="IsPressed" Value="true">
<Setter TargetName="Border" Property="Background" Value="{Binding RelativeSource={RelativeSource Self}, Path=Tag, Converter={StaticResource StatusToBrushConverter}}" />
</Trigger>
<Trigger Property="IsKeyboardFocused" Value="true">
<Setter TargetName="Border" Property="BorderBrush" Value="#202020" />
</Trigger>
<Trigger Property="IsDefaulted" Value="true">
<Setter TargetName="Border" Property="BorderBrush" Value="#202020" />
</Trigger>
<Trigger Property="IsEnabled" Value="false">
<Setter TargetName="Border" Property="Background" Value="#EEEEEE" />
<Setter TargetName="Border" Property="BorderBrush" Value="#AAAAAA" />
<Setter Property="Foreground" Value="#888888" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
转换器只工作一次。此外,任何属性更改标记都不会启动转换器。你有什么建议?