【发布时间】:2019-01-27 03:32:43
【问题描述】:
我使用了此代码,但在单击按钮后它不会恢复为默认样式。 我做错了什么?
<Style x:Key="normalImage" TargetType="{x:Type Image}">
<Setter Property="Source" Value="/SM-Works;component/Images/code_101.png"/>
</Style>
<Style x:Key="actionImage" TargetType="{x:Type Image}">
<Setter Property="Source" Value="/SM-Works;component/Images/code_10b.png"/>
</Style>
<Style x:Key="buttonstylesample" BasedOn="{StaticResource {x:Static ToolBar.ButtonStyleKey}}" TargetType="Button">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Grid>
<Image x:Name="img" Style="{DynamicResource normalImage}"/>
<Border
SnapsToDevicePixels="True"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderThickness}"
Padding="{TemplateBinding Padding}">
<ContentPresenter
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
</Border>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="Style" TargetName="img" Value="{DynamicResource actionImage}"/>
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter Property="Style" TargetName="img" Value="{DynamicResource actionImage}"/>
</Trigger>
<Trigger Property="IsKeyboardFocused" Value="True">
<Setter Property="Style" TargetName="img" Value="{DynamicResource actionImage}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
MouseOver,IsPressed 被激活,但是按下按钮后,按钮图像没有恢复正常。
【问题讨论】:
标签: wpf button properties styles