在WPF TreeViewItem中的图像上捕获鼠标指针/鼠标移动

在WPF TreeViewItem中的图像上捕获鼠标指针/鼠标移动,wpf,Wpf,我已经用XAML完成了我的TreeView,但是现在我想用代码隐藏来管理一个事件,我不知道怎么做。 HierarchycalDataTemplate包含一个图像。我需要在图像上捕捉MouseEnter/MouseLeave事件。我试过这样做: <Image x:Name="imgArticolo" Source="{Binding imgArt}"> <Image.Style TargetType="{x:Type Image}"> <Sty

我已经用XAML完成了我的TreeView,但是现在我想用代码隐藏来管理一个事件,我不知道怎么做。 HierarchycalDataTemplate包含一个图像。我需要在图像上捕捉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成员未被识别或无法访问”(来自意大利语)

你能帮帮我吗? 非常感谢。 皮莱吉


最终解决方案:

您的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>


非常感谢!它可以工作,但为什么在VisualStudio的设计器中出现错误:“无法使用EventSetter加载文件XAML”。我怎样才能补救?谢谢你,PileggiOk,你已经在这个链接上解决了我的问题: