本文介绍了Wpf - 在鼠标悬停时更改图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
亲爱的,
我想找到一种方法来改变鼠标悬停时的当前图像。
我正在使用以下代码,但它不起作用。
Dear all,
I am trying to figure a way to change the current image on mouseover.
I am using the following code but it doesn't work.
<Button x:Name="AnswerButton" Grid.Column="0" VerticalAlignment="Center" HorizontalContentAlignment="Center" Width="60" Height="60" Background="Transparent" IsEnabled="False" Click="AnswerButton_OnClick" BorderBrush="Transparent" BorderThickness="0">
<Image Source="/VeriPark.CTI.Demo;component/Images/Answer.PNG" Stretch="UniformToFill"/>
</Button>
<Style TargetType="{x:Type Image}">
<Setter Property="Source" Value="/VeriPark.CTI.Demo;component/Images/Answer.PNG"/>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Source" Value="/VeriPark.CTI.Demo;component/Images/answer-hover.PNG"/>
</Trigger>
</Style.Triggers>
</Style>
我的尝试:
尝试谷歌而没有运气,在不同的网站搜索
What I have tried:
Tried google and no luck, searched in different sites
推荐答案
<Style TargetType="{x:Type Button}">
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Content" >
<Setter.Value>
<Image Source="/VeriPark.CTI.Demo;component/Images/answer-hover.PNG" Stretch="UniformToFill"/>
</Setter.Value>
</Setter>
</Trigger>
</Style.Triggers>
</Style>
================== =================================
如果这对您有用,请标记作为答案。
===================================================
If that works for you, please mark it as an answer.
这篇关于Wpf - 在鼠标悬停时更改图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!