我有DataGridTextColumn.HeaderTemplate
:
<DataGrid ItemsSource="{Binding Persons}" AutoGenerateColumns="False">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding IdPerson}">
<DataGridTextColumn.HeaderTemplate>
<DataTemplate>
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Button Height="25" HorizontalAlignment="Stretch"/>
<TextBlock Grid.Row="1" Text = "Hello"/>
<CheckBox Grid.Row="2" IsChecked="True" />
</Grid>
</DataTemplate>
</DataGridTextColumn.HeaderTemplate>
</DataGridTextColumn>
<DataGridTextColumn Header="FirstName" Binding="{Binding FirstName}"/>
<DataGridTextColumn Header="LastName" Binding="{Binding LastName}"/>
</DataGrid.Columns>
</DataGrid>
但是,控件(Button, TextBlock, CheckBox
)未在<DataGridTextColumn.HeaderTemplate/>
内拉伸。
我所知道的:
如何在<DataGridTextColumn.HeaderTemplate/>
的整个长度范围内对<DataGridTextColumn.HeaderTemplate/>
内的所有控件进行拉伸?
答案 0 :(得分:1)
你可以设置这样的东西。
<DataGrid.Resources>
<Style TargetType="{x:Type DataGridColumnHeader}">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
</Style>
</DataGrid.Resources>