在WPF图像中显示鼠标上的不同图像 [英] Showing different image on mouse over in WPF Image

查看:139
本文介绍了在WPF图像中显示鼠标上的不同图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用于datagridtemplatecolumn的数据窗口

我试图在Image上鼠标上显示不同的图像。

鼠标悬停时,光标正在变化,但图像是不改变。

 <   DataTemplate     x:Key   =  MyDataTemplate    DataType   =  DataRowView >  
< StackPanel 方向 = 水平 已删除 = 透明 >
< 图片 保证金 = 0,0,0,0 宽度 = 50 高度 = 50 来源 = {Binding Converter = {StaticResource SetImgToDG}} 工具提示 = {Binding} >
< Image.Resources >
< 样式 TargetType = {x:Type Image} >
< Style.Triggers >
< 触发器 属性 = IsMouseOver < span class =code-attribute> = True >
<! - < span class =code-keyword> 悬停图片 - >
< Setter 属性 = 光标 = / >
< Setter 属性 = 来源 = C:\Images\Coil3.png / >
< / Trigger >
< / Style.Triggers < span class =code-keyword>>
< / Style >
< / Image.Resources < span class =code-keyword>>
< / Image >
< / StackPanel >
< / DataTemplate >





该绑定是否会产生问题??

如何解决??? div class =h2_lin>解决方案

你的setter看起来不对劲。您不能提供文件系统上的值,而是提供应用程序中资源的值。



http://www.codewrecks.com/blog/index.php/2010/07/23/bind-an-image-to-a-property-in-wpf/ [ ^ ]


I have a datatemplate used for datagridtemplatecolumn
I am trying to show different image on mouse over in Image.
On mouse over, the cursor is changing but image is not changing.

<DataTemplate x:Key="MyDataTemplate" DataType="DataRowView">
        <StackPanel Orientation="Horizontal" removed="Transparent">
            <Image Margin="0,0,0,0"   Width="50" Height="50" Source="{Binding Converter={StaticResource SetImgToDG}}" ToolTip="{Binding}" >
                <Image.Resources>
                    <Style TargetType="{x:Type Image}">
                        <Style.Triggers>
                            <Trigger Property="IsMouseOver" Value="True">
                                <!-- Hover image -->
                                <Setter Property="Cursor" Value="Hand"/>
                                <Setter Property="Source" Value="C:\Images\Coil3.png"/>
                            </Trigger>
                        </Style.Triggers>
                    </Style>
                </Image.Resources>
            </Image>
        </StackPanel>
    </DataTemplate>  



Is that binding creates the problem??
How to resolve it??

解决方案

Your setter looks wrong. You don''t provide values that are on the file system, but values that are resources in your app.

http://www.codewrecks.com/blog/index.php/2010/07/23/bind-an-image-to-a-property-in-wpf/[^]


这篇关于在WPF图像中显示鼠标上的不同图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆