WPF - Binding to current item from within group header style

前端 未结 2 2130
渐次进展
渐次进展 2021-02-14 21:53

I\'m something of a WPF noob so please take it easy on me ;-)

I am trying to create a grouped DataGrid (WPF toolkit version). I have successfully created the data sourc

2条回答
  •  后悔当初
    2021-02-14 22:02

    binding settings depend on the type of the Assign_To property. The simplest settings which could probably work for you would be:

    
    
    

    pls, check if an example below would work for you; also this link WPF Toolkit DataGrid Part IV: TemplateColumns and Row Grouping might be helpful for you

    code:

    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
    
            var dataProvider = (CollectionViewSource)FindResource("CVS");
            dataProvider.Source = Test.GetTests();
        }
    }
    
    public class Test
    {
        public string   Assign_To { get; set; }
        public string   Test0 { get; set; }
        public int      Test1 { get; set; }
    
        public static List GetTests()
        {
            List tests = new List();
    
            tests.Add(new Test { Assign_To = "a", Test0 = "aaaa", Test1 = 1 });
            tests.Add(new Test { Assign_To = "a", Test0 = "bbbb", Test1 = 1 });
            tests.Add(new Test { Assign_To = "b", Test0 = "cccc", Test1 = 2 });
    
            return tests;
        }
    }
    

    xaml:

        
        
            
                
            
        
    
            
    
    
            
            
            
                
                    
                        
                            
                        
                    
                
                
            
                
                
            
        
    
    

提交回复
热议问题