title: WPF - DataGrid Custom Binding - List of Custom Objects with dynamic number of properties - C#
body: <p>Using Linq pad I created a view on data in the database which I now hope to replicate in a WPF Application.</p>
  
  <p>I took advantage of the Linq <code>Dump()</code> method. By implementing <code>ICustomMemberProvider</code> I could provide the column headers, types and values which I wanted to be output. The three methods I needed to implement were;</p>
  
  <pre><code>   public IEnumerable&lt;string&gt; GetNames() 
     public IEnumerable&lt;Type&gt; GetTypes()
     public IEnumerable&lt;object&gt; GetValues()
  </code></pre>
  
  <p>This was a simple, quick and clean way of describing what the <code>Dump()</code>' for single or multiple rows should be.</p>
  
  <p>For the life of me I cannot find anything as straight forward in WPF. I have a dynamic (per run not per row) number of Columns and so I can't hard code Column titles and binding paths, there may be 5 columns and there may be 20.</p>
  
  <p>I was pointed towards <a href="http://msdn.microsoft.com/en-us/library/system.componentmodel.icustomtypedescriptor.aspx" rel="nofollow">ICustomTypeDescriptor</a> but I need a concrete example of how that would work as there are so many methods in that interface.</p>
  
  <p>I'm really hoping there's something simpler that I've missed which will allow me to implement dynamically what the rows and columns should contain given an <code>IEnumerable</code> of my custom class.</p>
  
  <p>Any links to a tutorial or overview of how this is meant to work would be greatly appreciated. I have been surprised by the lack of documentation I've found so I must be using the wrong terms.</p>
  
  <p>For clarity the source of a single row is an instance of a class like this;</p>
  
  <pre><code>public class CustomDatum 
  {
     public string ID {get; private set;}
     public string Location {get; private set;}
  
     public IEnumerable&lt;Attributes&gt; attributes {get; private set;}
  
     public class Attribute 
     {
         public string Name {get; private set;}
         public string Value {get; private set;}
  
         public override ToString()
         {
             ....
         }
     }
  }
  </code></pre>
  
  <p>I want to display the ID, Location and all attributes in a single Row, I have an <code>IEnumerable&lt;CustomDatum&gt;</code> to bind to. The actual class is a lot more complex than this example naturally.</p>
  
  <p>Thanks!</p>