在 xaml 中单击时如何更改按钮图像 [英] How to change button image when clicked in xaml
本文介绍了在 xaml 中单击时如何更改按钮图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当用户将鼠标悬停在按钮上时,我可以像在 XAML 中那样更改按钮的图像:
When the user hovers over a button I can change the image of the button like so in XAML:
<Page.Resources>
<ImageBrush x:Key="troubleshooting_normal" ImageSource="/Images/troubleshooting_yellow.png" />
<ImageBrush x:Key="troubleshooting_hover" ImageSource="/Images/troubleshooting_gray.png" />
<ControlTemplate TargetType="Button" x:Key="buttonTroubleshooting">
<Grid Name="button" Background="{StaticResource troubleshooting_normal}">
<ContentPresenter/>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="button" Property="Background" Value="{StaticResource troubleshooting_hover}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Page.Resources>
<Button Name="ButtonTroubleShooting" Template="{StaticResource buttonTroubleshooting}" HorizontalAlignment="Left" Margin="287,109,0,0" VerticalAlignment="Top" Width="155" Height="155" Click="ButtonTroubleShooting_Click"/>
我想在用户点击按钮时添加第三张图片,我该如何修改上面的内容来做到这一点??
I want to add a 3rd image for when the user clicks on the button, how do I modify the above to do this??
推荐答案
只需添加另一个触发器,基于 IsPressed
属性:
Simply add another trigger, based on the IsPressed
property:
<Trigger Property="IsPressed" Value="True">
<Setter TargetName="button" Property="Background" Value="{StaticResource troubleshooting_pressed}" />
</Trigger>
这篇关于在 xaml 中单击时如何更改按钮图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文