user2096837
user2096837

Reputation: 105

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

Upvotes: 9

Views: 16646

Answers (1)

Clemens
Clemens

Reputation: 128013

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>

Upvotes: 33

Related Questions