Merge Cells in WPF DataGrid

后端 未结 3 1579
无人共我
无人共我 2020-12-01 16:38

I want to create a WPF datagrid that spans over multiple rows in one column. Like this:

+-------+----------------+
| Name  | Attributes     |
+-------+------         


        
3条回答
  •  南方客
    南方客 (楼主)
    2020-12-01 16:57

    Try use DataGridTemplateColumn. I created sample test class for databinding

    public class Test
    {
    
        public Test(string name, string attribute1, string attribute2)
        {
            Name = name;
            Attributes = new Attribute(attribute1, attribute2);
        }
    
        public string Name { get; set; }
        public Attribute Attributes { get; set; }
    }
    
    public class Attribute
    {
    
        public Attribute(string attribute1, string attribute2)
        {
            Attribute1 = attribute1;
            Attribute2 = attribute2;
        }
    
        public string Attribute1 { get; set; }
        public string Attribute2 { get; set; }
    }
    

    And a datagrid in xaml

    
            
                
                    
                        
                            
                                
                            
                        
                    
                
                
                    
                        
                            
                                
                                    
                                    
                                    
                                
                                
                                
                                
                            
                        
                    
                
            
        
    

    And fill it in code-behind

    List list = new List();
    //populate list with your data here
    dataGrid1.DataContext = list;
    

提交回复
热议问题