I have a DataTemplate for a gridview column, it has 2 items in it, an image and a text block, I want to "lock" the image to the left side of the column, even if开发者_开发知识库 the user expand the width of the column, I want the image to stay put.
any ideas ?
Try to set HorizontalContentAlignment
to Stretch for GridViewColumnHeader
<ListView ...>
<ListView.Resources>
<Style TargetType="{x:Type GridViewColumnHeader}">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
</Style>
</ListView.Resources>
<!--...-->
</ListView>
Then your HeaderTemplate can look something like this if you want the TextBlock
to be centered. Otherwise just remove the HorizontalAlignment
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Image Grid.Column="0" .../>
<TextBlock Grid.Column="1" HorizontalAlignment="Center" .../>
</Grid>
</DataTemplate>
精彩评论