title: WPF DataGrid and ITypedList
body: <p>I tried to implement <code>ITypedList</code> in my <code>ItemsSource</code>but <code>PropertyDescriptor.GetValue/SetValue</code> are never invoked. What is wrong about it?</p>
  
  <p>XAML looks like this:</p>
  
  <pre><code>&lt;Window x:Class="WpfApplication5.MainWindow"
          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
          xmlns:sys="clr-namespace:System;assembly=mscorlib"
          xmlns:local="clr-namespace:WpfApplication5"
          Title="MainWindow" Height="350" Width="525"&gt;
      &lt;Grid&gt;
          &lt;DataGrid AutoGenerateColumns="True"&gt;
              &lt;DataGrid.ItemsSource&gt;
                  &lt;local:RowCollection/&gt;
              &lt;/DataGrid.ItemsSource&gt;
          &lt;/DataGrid&gt;
      &lt;/Grid&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p>RowCollection is defined as:</p>
  
  <pre><code>public class RowCollection : ReadOnlyCollection&lt;Row&gt;, ITypedList {
      readonly PropertyDescriptorCollection _properties;
  
      public RowCollection() : base(new List&lt;Row&gt;()) {
          _properties = new PropertyDescriptorCollection(new[] {
                  new RowDescriptor("Name"),
                  new RowDescriptor("Value")
          }, true);
  
          Items.Add(new Row());
          Items.Add(new Row());
      }
  
      PropertyDescriptorCollection ITypedList.GetItemProperties(PropertyDescriptor[] listAccessors) {
          return _properties;
      }
  
      string ITypedList.GetListName(PropertyDescriptor[] listAccessors) {
          return null;
      }
  }
  </code></pre>
  
  <p>Where RowDescriptor is:</p>
  
  <pre><code>public class RowDescriptor : PropertyDescriptor {
      public RowDescriptor(string name) 
          : base(name, new Attribute[0]) {
      }
  
      public override bool CanResetValue(object component) {
          return false;
      }
  
      public override Type ComponentType {
          get { return typeof(Row); }
      }
  
      public override object GetValue(object component) {
          var row = (Row)component;
          return row[Name];
      }
  
      public override bool IsReadOnly {
          get { return false; }
      }
  
      public override Type PropertyType {
          get { return typeof(string); }
      }
  
      public override void ResetValue(object component) {
          throw new NotSupportedException();
      }
  
      public override void SetValue(object component, object value) {
          var row = (Row)component;
          row[Name] = String.Format("{0}", value ?? String.Empty);
      }
  
      public override bool ShouldSerializeValue(object component) {
          return false;
      }
  }
  </code></pre>
  
  <p>And Row is:</p>
  
  <pre><code>public class Row {        
      readonly Dictionary&lt;string, string&gt; _values;
  
      public Row() {
          _values = new Dictionary&lt;string, string&gt;();
          this["Name"] = "Foo";
          this["Value"] = "Bar";
      }
  
      public string this[string name] {
          get {
              if (!_values.ContainsKey(name))
                  return String.Empty;
  
              return _values[name];
          }
          set {
              _values[name] = value;
          }
      }
  }
  </code></pre>