次の方法で共有


Autogeneration of a WPF data grid fails

Brushing off my coding skills & got stuck for a bit on a failure to autogenerate a Data Grid’s columns. I got plenty of rows, but no columns. The secret is to ensure that your base object has publicly available members. Don’t get lazy and just expose properties.

In my example, I used a List<AppOrderingItem> as my data source. Autogeneration failed when an AppOrderingItem was

    1:  class AppOrderingItem 
    2:  { 
    3:      public string appName;
    4:   
    5:      public int numUsers; 
    6:  }
    7:   

but works great with

    1:  class AppOrderingItem 
    2:  { 
    3:      public string appName {get;set;} 
    4:      public int numUsers { get; set; }
    5:   
    6:  } 
    7:   

 

Makes sense, and a great way to punish my laziness. :)