I have a ListView on my form and I'm setting up the ListView.HeaderTemplate and it looks like what I expect it to look like.
However, if I copy the exact Grid definition into my ListView.ItemTemplate it does not layout the same.
Altered Two Column Value Colors (Cyan and Green)
I have altered the color of the two Item column values so you can differentiate where each is showing up. I have two <x:String>
values defined so data will show up in the preview layout of Visual Studio but when it runs the two layouts still look different even though they are defined the same.
No Grid.Row Defined On ItemTemplate TextBlocks
The one difference you'll notice in the XAML is that the ItemTemplate TextBlocks each only have its Grid.Column set (no Grid.Row set). That was a test and it looks the same either way.
Literally Copy / Pasted HeaderTemplate to ItemTemplate
I literally copied the HeaderTemplate to the ItemTemplate and made only the changes mentioned.
Why don't they layout the same?
<ListView.HeaderTemplate>
<DataTemplate>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBlock Margin="7 0 0 0" Grid.Row="0" Grid.Column="0" Foreground="#ff0000" Text="Date" />
<TextBlock Margin="0 0 15 0" Grid.Row="0" Grid.Column="1" Foreground="#ff0000" Text="Entry Count" />
</Grid>
</DataTemplate>
</ListView.HeaderTemplate>
EDIT
If I change the ItemTemplate ColumnDefinitions to look like the following:
<Grid.ColumnDefinitions>
<ColumnDefinition Width="200" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
Then it does get closer to what I expect, but I'm still not sure why I have to do this differently.