Reputation: 3697
I'm really going mad ... but the whole evening I'm trying to create a 3 column listbox. I want that the 3 columns are spread over the whole size of the listbox and not sticked together like they do when using the code below.
So, here's my XML
<ListBox Background="Red" HorizontalContentAlignment="Stretch"
ItemsSource="{Binding ListItems}"
>
<ListBox.ItemTemplate>
<DataTemplate>
<Grid HorizontalAlignment="Stretch" Background="Aquamarine">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Text="A"/>
<TextBlock Grid.Column="1" Text="B"/>
<TextBlock Grid.Column="2" Text="C"/>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Hope you can help me.
Upvotes: 0
Views: 2277
Reputation: 109289
If you set the Width
attribute of a ColumnDefinition
to Auto
that column will only use the minimum required width. Change the width of all 3 columns to *
.
Also try setting the HorizontalAlignment
attribute of the 3 TextBlock
s to Center
.
Upvotes: 1