tags:

views:

63

answers:

1

Hi!

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="{Binding 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:

A: 

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>
Joseph Sturtevant
Thank you very much! It works, but why in the designer of Visual Studio appear the error: "Impossible to load a file XAML with EventSetter". How can I remedy?Thank you,Pileggi
pileggi
Ok, you have resolved my problem at this link:http://stackoverflow.com/questions/2995730/eventsetter-error-xaml-in-visual-studio-designer
pileggi