views:

355

answers:

2

Hi,

I am using event triggers in my XAML, I have the following style set on a ListItem. What I want is to display the contents of the ListItem in a message box when the mouse enters a list item.

        <Style.Triggers>
            <EventTrigger RoutedEvent="Mouse.MouseEnter">

            </EventTrigger>
        </Style.Triggers>

I am wondering if its possible to fire code behind when the mouse enters the listitem.

+3  A: 
<ListBox>
    <ListBox.ItemContainerStyle>
        <Style TargetType="ListBoxItem">
            <EventSetter Event="MouseEnter" Handler="_listBoxItem_MouseEnter"/>
        </Style>
    </ListBox.ItemContainerStyle>
</ListBox>

HTH, Kent

Kent Boogaart
Hi Kent, Thank you that does help. However when I cast the sender to my custom object [Person p = sender as Person]; I get a null in the object "p". The class Person has a BitmapImage and a String holding the info to the image and this info is what I want to show in the messagebox. Any pointers?
Anand
Hi Anand. The sender will be the ListBoxItem. You can cast sender to ListBoxItem and then cast the DataContext of the ListBoxItem to your Person class.
Kent Boogaart
Hi Kent, Thanks a lot, what I did was to override the ToString method in the Person class to return the necessary string. But your solution is much more better than overriding ToString. :-)
Anand
A: 

hi, i have the same problem, but when i tried to as Kent showed, the EventSetter cant be found! am using an autocompletebox in Silvelright 3 and i tried to change its listbox. can you help me plz

Thanx

yoBina
Hi, I don't have any experience with Silverlight. But if you paste some sample code, then I can have a look at it
Anand