capture MouseEnter / MouseLeave on Image in WPF TreeViewItem
I've done my TreeView all with XAML but now I'd like to manage an event with code-behind and I don't know how. The HierarchicalDataTemplate contains an Image. I need to capture the events MouseEnter / MouseLeave on the Image. I've tried in this way:
<Image x:Name="imgArticolo" Source="{Bi开发者_JAVA百科nding imgArt}">
<Image.Style TargetType="{x:Type Image}">
<Style>
<EventSetter Event="MouseEnter" Handler="iArt_MouseEnter"/>
</Style>
</Image.Style>
</Image>
But it doesn't work: error: "MouseEnter member not recognized or not accessible" (from italian)
Can you, please, help me? Thank you! Pileggi
The final solution here:
You have an error in your XAML. The TargetType
attribute goes in the Style
tag, not the Image.Style
tag. If you fix this, it should work properly like so:
<Image x:Name="imgArticolo" Source="{Binding imgArt}">
<Image.Style>
<Style TargetType="{x:Type Image}">
<EventSetter Event="MouseEnter" Handler="iArt_MouseEnter"/>
</Style>
</Image.Style>
</Image>
精彩评论