【发布时间】:2011-07-13 10:56:12
【问题描述】:
我有一个button 的样式,如下所示。
<Style TargetType="Button" x:Key="TransparentButton">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border HorizontalAlignment="Center" x:Name="borderTemplate"
Background="Transparent">
<ContentPresenter/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter TargetName="borderTemplate"
Property="Border.BorderBrush" Value="Gray" />
<Setter TargetName="borderTemplate"
Property="Border.BorderThickness" Value="1" />
</Trigger>
<Trigger Property="IsPressed" Value="true">
<Setter TargetName="borderTemplate"
Property="Border.BorderBrush" Value="Lime" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
我需要设置button的background
1.在“MouseUp”事件发生时灰色。
2.一旦按钮焦点被更改或说焦点丢失,立即将其设置为默认(比如白色)。
有没有办法使用Trigger 或EventTrigger 解决这个问题??
请参阅一个示例以了解上述带有图像的代码
上面样式的按钮。
<Button Background="Black" Style="{StaticResource TransparentButton}"
Content="0123456789" Height="15" HorizontalAlignment="Left"
Name="button2" VerticalAlignment="Top" Margin="70,17,0,0" />
应用上述样式后,按钮将如下图所示。
【问题讨论】: