放入DataGrid的<datagridtextcolumn.headertemplate>的按钮不会填充所有可用空间

时间:2016-03-01 09:06:31

标签: c# wpf datagrid

我有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/>内拉伸。

我所知道的:

enter image description here

如何在<DataGridTextColumn.HeaderTemplate/>的整个长度范围内对<DataGridTextColumn.HeaderTemplate/>内的所有控件进行拉伸?

1 个答案:

答案 0 :(得分:1)

你可以设置这样的东西。

<DataGrid.Resources>
    <Style TargetType="{x:Type DataGridColumnHeader}">
        <Setter Property="HorizontalContentAlignment" Value="Stretch" />
    </Style>
</DataGrid.Resources>