简体   繁体   中英

How to set TextBox to be resized when DataGridTemplateColumn size changes

I tried some stuff but all didn't work. Maybe I missed something. The goal is to have to fill horizontally column with TextEdit and have it autoresized when user change column size by dragging.

<DataGrid>
   <DataGrid.Columns>
       <DataGridTemplateColumn Width="200">
             <DataGridTemplateColumn.HeaderTemplate>
                        <DataTemplate>
                            <TextBox/>
                        </DataTemplate>
             </DataGridTemplateColumn.HeaderTemplate>
       </DataGridTemplateColumn>
   </DataGrid.Columns>
</DataGrid>

Add a Header Style to your DataGrid .

<DataGridTemplateColumn Width="200">
    <DataGridTemplateColumn.HeaderStyle>
         <Style TargetType="{x:Type DataGridColumnHeader}">
              <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
         </Style>
    </DataGridTemplateColumn.HeaderStyle>
    <DataGridTemplateColumn.HeaderTemplate>
        ...
    </DataGridTemplateColumn.HeaderTemplate>
    ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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