Reputation: 55
I'm using a HeaderedItemsControl to show person names. I also want to show a header that contains 3 labels: Title, First Name and Last Name. This is easy when the names are short. However, when there is a very long firstname, the header's don't match the names anymore. How can I fix this? Thank you!
Upvotes: 3
Views: 2644
Reputation: 184524
Not sure if you really want to use this class:
A HeaderedItemsControl has a limited default style. To create a HeaderedItemsControl with a custom appearance, create a new ControlTemplate.
Anyway, to line up stuff you can use Grids with shared size, e.g.:
<HeaderedItemsControl ItemsSource="{Binding Data}" Grid.IsSharedSizeScope="True">
<HeaderedItemsControl.Template>
<ControlTemplate TargetType="HeaderedItemsControl">
<StackPanel>
<ContentPresenter ContentSource="Header" />
<ItemsPresenter />
</StackPanel>
</ControlTemplate>
</HeaderedItemsControl.Template>
<HeaderedItemsControl.Header>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition SharedSizeGroup="A" />
<ColumnDefinition SharedSizeGroup="B" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Text="Name" />
<TextBlock Grid.Column="1" Text="Occupation" />
</Grid>
</HeaderedItemsControl.Header>
<HeaderedItemsControl.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition SharedSizeGroup="A" />
<ColumnDefinition SharedSizeGroup="B" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Text="{Binding Name}"/>
<TextBlock Grid.Column="1" Text="{Binding Occupation}" />
</Grid>
</DataTemplate>
</HeaderedItemsControl.ItemTemplate>
</HeaderedItemsControl>
Upvotes: 7