我想要覆盖默认按钮样式,以便只有一个图像按钮,没有边框和所有这些东西。
这一切都很好,但是虽然我在我的 XAML 样式中定义了 VisualStateManager,但无法用鼠标按下按钮。事实上,它什么也没做。
我做错了什么?
<!-- Button Style -->
<Style x:Key="WinImageButton" TargetType="Button">
<Setter Property="BorderBrush" Value="Transparent"/>
<Setter Property="BorderThickness" Value="0" />
<Setter Property="Background" Value="Transparent"/>
<Setter Property="RenderTransform">
<Setter.Value>
<TranslateTransform/>
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<ContentControl x:Name="RootElement">
<ContentPresenter
HorizontalAlignment="Center"
VerticalAlignment="Center"
RecognizesAccessKey="True">
</ContentPresenter>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup Name="CommonStates">
<VisualState Name="Normal" />
<VisualState Name="Pressed">
<Storyboard>
<DoubleAnimation
Storyboard.TargetName="RootElement"
Storyboard.TargetProperty="(FrameworkElement.RenderTransform).(TranslateTransform.Y)"
To="2.0" />
<DoubleAnimation
Storyboard.TargetName="RootElement"
Storyboard.TargetProperty="(FrameworkElement.RenderTransform).(TranslateTransform.X)"
To="-2.0" />
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</ContentControl >
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>