Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mouseover to select item in listbox in WPF

I am relatively new to WPF, but I would like to know how can I enable a listbox to select an item based on a mouseover event instead of the button click. I would like the item to be selected when the mouse is over the selected item, without having to press click first.

Thank you

like image 651
user2096837 Avatar asked Mar 19 '13 22:03

user2096837


1 Answers

You may write a simple ListBoxItem Style with a Trigger on the IsMouseOver property that sets the IsSelected property:

<ListBox>
    <ListBox.ItemContainerStyle>
        <Style TargetType="ListBoxItem">
            <Style.Triggers>
                <Trigger Property="IsMouseOver" Value="True">
                    <Setter Property="IsSelected" Value="True"/>
                </Trigger>
            </Style.Triggers>
        </Style>
    </ListBox.ItemContainerStyle>
</ListBox>
like image 110
Clemens Avatar answered Oct 04 '22 22:10

Clemens