Stretch ListBox Items hit area to full width if the ListBox?
Posted
by
Nicholas
on Stack Overflow
See other posts from Stack Overflow
or by Nicholas
Published on 2011-01-08T13:59:39Z
Indexed on
2011/01/08
14:54 UTC
Read the original article
Hit count: 198
I've looked around for an answer on this, but the potential duplicates are more concerned with presentation than interaction.
I have a basic list box, and each item's content is a simple string.
The ListBox itself is stretched to fill it's grid container, but each ListBoxItem's hitarea does not mirror the ListBox width. It looks as if the hitarea (pointer contact area) for each item is only the width of the text content. How do I make this stretch all the way across, regardless of the text size.
I've set HorizontalContentAlignment to Stretch, but this doesn't solve my problem. My only other guess is that the content is actually stretching, but the background is invisible and so not capturing the mouse pointer.
<ListBox
Grid.Row="1"
x:Name="ProjectsListBox"
DisplayMemberPath="Name"
ItemsSource="{Binding Path=Projects}"
SelectedItem="{Binding Path=SelectedProject}"
HorizontalContentAlignment="Stretch"/>
The XAML is pretty straight forward on this. If I mouse over the text in one of the items, then the entire width of the item becomes active. I guess I just need to know how to create an interactive background that is invisible.
© Stack Overflow or respective owner