$ cat "

Getting a ListBoxItem to stretch horizontally in Silverlight


When you specify an ItemTemplate for a ListBox in silverlight, you can't get it to stretch horizontally in an easy way. Setting the HorizontalAlignment of the container in the template to stretch has no effect. What you have to do is to specify an ItemContainerStyle for the ListBox and set the HorizontalContentAlignment to Stretch:

<ListBox ItemsSource="{Binding Users}" SelectedItem="{Binding SelectedUser, Mode=TwoWay}">
<Style TargetType="ListBoxItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Border BorderThickness="1" BorderBrush="#CECECE" Padding="5" CornerRadius="3"
Background="{Binding Background}">
<!-- Your stuff here -->

Written by Erik Öjebo 2011-11-29 08:05