简体   繁体   English

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

[英]Button placed into <DataGridTextColumn.HeaderTemplate> of DataGrid does not fill all available space

I have such a DataGridTextColumn.HeaderTemplate : 我有这样一个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>  

However, the controls( Button, TextBlock, CheckBox ) are not stretched inside of <DataGridTextColumn.HeaderTemplate/> . 但是,控件( Button, TextBlock, CheckBox )未在<DataGridTextColumn.HeaderTemplate/>内部扩展。

What I have know: 我所知道的:

在此处输入图片说明

How can I make all controls inside of <DataGridTextColumn.HeaderTemplate/> to be stretched on the whole length of <DataGridTextColumn.HeaderTemplate/> ? 我怎样才能使内部的所有控件<DataGridTextColumn.HeaderTemplate/>要在整个长度拉伸<DataGridTextColumn.HeaderTemplate/>

You could set something like this. 您可以设置像这样的东西。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM