Silverlight: stretch ListBoxItem horizontally.

Very often you need to stretch your ListBoxItem horizontally. If the ListBox is simple (without ItemTemplate), there is easy solution: just add

HorizontalContentAlignment="Stretch"

to the ListBox.

However, in second way the solution is easy too. But frequently we spend a lot of time to fix it. There is a solution:

<ListBox.ItemContainerStyle>
<Style TargetType=”ListBoxItem”>
<Setter Property=”HorizontalContentAlignment” Value=”Stretch”></Setter>
</Style>
</ListBox.ItemContainerStyle>

Enjoy!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s