如何将鼠标悬停在WPF上的图像更改? [英] How do I change an image on hover over in WPF?
本文介绍了如何将鼠标悬停在WPF上的图像更改?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
到目前为止,我所拥有的只是:
pre> < Image Height =32Source =/ images / Save32.png/>
解决方案
您需要在IsMouseOver属性上使用触发器修改图片的来源:
<图片>
< Image.Style>
< Style TargetType ={x:Type Image}>
< Setter Property =SourceValue =C:\Image1.jpg/>
< Style.Triggers>
<触发属性=IsMouseOver值=真>
< Setter Property =SourceValue =C:\Image2.jpg/>
< /触发>
< / style>
< /图片>
请注意,触发器只能在样式中使用,并且为了让触发器更改属性属性的值必须由Style设置,而不是在元素上明确设置。
How can I change an image when I hover over it?
All I have so far is:
<Image Height="32" Source="/images/Save32.png" />
解决方案
You need to use a Trigger on the IsMouseOver property to modify the Source of the Image:
<Image>
<Image.Style>
<Style TargetType="{x:Type Image}">
<Setter Property="Source" Value="C:\Image1.jpg"/>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Source" Value="C:\Image2.jpg"/>
</Trigger>
</Style.Triggers>
</Style>
</Image.Style>
</Image>
Note that Triggers can only be used inside Styles, and in order for a Trigger to change a property that property's value must be set by the Style and not set explicitly on the element.
这篇关于如何将鼠标悬停在WPF上的图像更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文