VisualStateManager 似乎不适用于 .NET 4.0 (wpf)
我想覆盖默认按钮样式,以便只有一个图像按钮,没有边框和所有这些东西。
这一切都工作得很好,但是尽管我在 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>
I wanto to override the Default Button Style in order to have only an image button, without a border and all that stuff.
That's all working perfectly, but although I defined the VisualStateManager in my XAML Style, the button can't be pressed with the mouse. In fact, it does nothing.
What do I do wrong?
<!-- 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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否尝试过将 TranslateTransition 移动到 ControlTemplate 本身内部? (您可以将其放在模板的资源部分中。)
Have you tried moving the TranslateTransition to inside the ControlTemplate itself? (You can put it in the resources section of the template.)