WPF datagrid column heading span more than once column

后端 未结 6 586
轮回少年
轮回少年 2020-12-30 17:14

In a WPF datagrid is it possible to group column headings?

What I\'m after is

| Column 1 | Column 2 | Column 3|
| a  b  c  | a  b  c  | a  b  c |
|          


        
6条回答
  •  既然无缘
    2020-12-30 17:43

    This question is a bit old, but it was one of the first google results that came up when I was looking for a solution to this problem, and I don't like either answer posted here. So here's a simple alternative using a custom Header and ClipToBounds=False.

    
        
            
            
                
            
        
    
    

    The only thing you need to do is ensure that the combined width of whatever columns this header is spamming is at least the width of the header column.

    The TextBlock that contains the first character of the header text and Canvas.Height binding is used to block out the height needed for the header. It is only needed if your full datagrid header does not have an element that defines the header height, or if the header spamming multiple columns is bigger than the rest of them (which was my case... this was the only header column with bold text)

提交回复
热议问题