03 January 2011

XAML - Horizontal align stretch for item template

To get the content of the item template in a listbox to stretch along with the listbox itself:
Source (answer 2)

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

Other properties of the listbox items can also be set here:

<Setter Property="IsEnabled" Value="False" />

Apparantly, however, you can't use bindings in these setters, while WPF does allow this.

But there is a workaround involving some coding that resolves the issue.

No comments:

Post a Comment