【问题标题】:capture MouseEnter / MouseLeave on Image in WPF TreeViewItem在 WPF TreeViewItem 中的图像上捕获 MouseEnter / MouseLeave
【发布时间】:2010-06-07 21:55:09
【问题描述】:

我已经用 XAML 完成了我的 TreeView,但现在我想用代码隐藏来管理一个事件,但我不知道该怎么做。 HierarchicalDataTemplate 包含一个图像。我需要在图像上捕获事件 MouseEnter / MouseLeave。我试过这样:

<Image x:Name="imgArticolo" Source="{Binding imgArt}">
    <Image.Style TargetType="{x:Type Image}">
        <Style>
            <EventSetter Event="MouseEnter" Handler="iArt_MouseEnter"/>
        </Style>
    </Image.Style>
</Image>

但它不起作用:错误:“MouseEnter 成员无法识别或无法访问”(来自意大利语)

请你帮帮我好吗? 谢谢! 皮莱吉

最终解决方案here:

【问题讨论】:

    标签: wpf


    【解决方案1】:

    您的 XAML 中有错误。 TargetType 属性位于 Style 标记中,而不是 Image.Style 标记中。如果你解决了这个问题,它应该像这样正常工作:

    <Image x:Name="imgArticolo" Source="{Binding imgArt}">
        <Image.Style>
            <Style TargetType="{x:Type Image}">
                <EventSetter Event="MouseEnter" Handler="iArt_MouseEnter"/>
            </Style>
        </Image.Style>
    </Image>
    

    【讨论】:

    • 非常感谢!它可以工作,但为什么在 Visual Studio 的设计器中出现错误:“无法使用 EventSetter 加载文件 XAML”。我该如何补救?谢谢你,Pileggi
    • 好的,你已经通过这个链接解决了我的问题:stackoverflow.com/questions/2995730/…
    猜你喜欢
    • 1970-01-01
    • 2023-03-28
    • 2010-11-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-30
    • 1970-01-01
    相关资源
    最近更新 更多