How do I enable text wrapping on all column headers?

前端 未结 5 1108
无人及你
无人及你 2021-01-03 18:14

How does one enable text wrapping on all column headers of a DataGrid, without disabling the other default header functionality? Such as column resizing, sort d

5条回答
  •  孤独总比滥情好
    2021-01-03 18:40

    I would like to enable text wrapping on all column headers of my DataGrid, without disabling the other default header functionality

    You need to add the following namespace to your app.xaml file:

    xmlns:primitives="clr-namespace:Microsoft.Windows.Controls.Primitives;assembly=WPFToolkit"
    

    and then add this tag to app.xaml:

    
    

    This will add text-wrapping to the headers of all of your DataGrids throughout your WPF application.

    While we're on the subject, if you just wanted to center the text of each of your DataGrid headers, you could do this using the following style instead:

    
    

    Yet I've seen so many WPF articles suggesting that you can only do this by adding TextWrapping or HorizontalAlignment on each DataGrid column individually:

    
        
            
                
            
        
    
    

提交回复
热议问题