动画图像按钮
我需要有关我已经使用了一段时间的自定义“图像按钮”的帮助。它工作得很好,但我不知道如何用这三种状态(正常、鼠标悬停、按下)对按钮进行动画处理:
- 正常到 MouseOver
- 、MouseOver 到按下
我对 XAML 不太熟练,所以我无法弄清楚。无论如何,这是我一直在使用的代码:
<Button Height="40" HorizontalAlignment="Left" IsEnabled="True" IsHitTestVisible="True" Margin="262,219,0,0" Name="home_btn" VerticalAlignment="Top" Width="89">
<Button.Template>
<ControlTemplate TargetType="{x:Type Button}">
<Grid>
<Image Name="Normal" Source="normal.png" />
<Image Name="Hover" Source="hover.png" Visibility="Hidden" />
<Image Name="Pressed" Source="pressed.png" Visibility="Hidden" />
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="ButtonBase.IsPressed" Value="True">
<Setter Property="UIElement.Visibility" TargetName="Normal" Value="Hidden" />
<Setter Property="UIElement.Visibility" TargetName="Pressed" Value="Visible" />
</Trigger>
<Trigger Property="UIElement.IsMouseOver" Value="True">
<Setter Property="UIElement.Visibility" TargetName="Normal" Value="Hidden" />
<Setter Property="UIElement.Visibility" TargetName="Hover" Value="Visible" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Button.Template>
</Button>
任何答案都会受到赞赏。
I need help with an custom "Image-Button" that i have used for a while. It works great, but i can't figure out how to animate the button with these three states (normal, mouseover, pressed):
- Normal to MouseOver
- MouseOver to Pressed
Im not that skilled with XAML so I couldn't figure it out. Anyway here's the code i've been using:
<Button Height="40" HorizontalAlignment="Left" IsEnabled="True" IsHitTestVisible="True" Margin="262,219,0,0" Name="home_btn" VerticalAlignment="Top" Width="89">
<Button.Template>
<ControlTemplate TargetType="{x:Type Button}">
<Grid>
<Image Name="Normal" Source="normal.png" />
<Image Name="Hover" Source="hover.png" Visibility="Hidden" />
<Image Name="Pressed" Source="pressed.png" Visibility="Hidden" />
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="ButtonBase.IsPressed" Value="True">
<Setter Property="UIElement.Visibility" TargetName="Normal" Value="Hidden" />
<Setter Property="UIElement.Visibility" TargetName="Pressed" Value="Visible" />
</Trigger>
<Trigger Property="UIElement.IsMouseOver" Value="True">
<Setter Property="UIElement.Visibility" TargetName="Normal" Value="Hidden" />
<Setter Property="UIElement.Visibility" TargetName="Hover" Value="Visible" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Button.Template>
</Button>
Any answer is appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
完成动画的另一种方法是使用触发器,就像结合 故事板
这是一些示例代码(集成在您发布的代码中):
An other way to accomplish animation is to use triggers like you did in combination with Storyboards
Here is some sample code (integrated in your posted code):
您可能应该使用
VisualStateManager
对于此类事情,请参阅其文档以获取使用示例。You should probably use the
VisualStateManager
for that sort of thing, see its documentation for a usage example.