Can static data for Datagrid rows be defined purely in XAML i.e. no code behind?

后端 未结 3 1262
伪装坚强ぢ
伪装坚强ぢ 2020-12-31 04:41

I have static data that I want to display in Datagrid format. The values are for display purposes only and will not change. Can it be added as some kind of subtag of the Dat

3条回答
  •  隐瞒了意图╮
    2020-12-31 04:54

    Here is pure XAML static data binded on a datagrid:

    
    
        
            
                
                    
                    
                    
                
            
        
    
    
        
            
                
                
                
            
        
    
    

    Result:

    enter image description here

    I wasn't able to autogenerate columns using XmlDataProvider (I'm probably missing something):

    
        
        
    
    

    enter image description here

    But using a code Behind class like Dave Suggestion allow AutoBinding to work and in my opinion is much simpler (I preferred the ResourceDictionary approach though) :

    Code:

    namespace WpfStaticDataBinding
    {
        public class MockRecord
        {
            public string FirstName { get; set; }
            public string LastName { get; set; }
            public string Email { get; set; }
        }
    }
    

    XAML

    
    
        
            
                
                
                
            
        
    
    
        
    
    

提交回复
热议问题