title: How to create a custom property editor for Extended WPF Toolkit PropertyGrid with another (nested) editor in C#?
body: <p>I have following generic class:</p>
  
  <pre><code>public class Member&lt;T&gt;
  {
      public bool IsDirty { get; set; }
      public T Value { get; set; }
  }
  </code></pre>
  
  <p>I want to create a custom editor for the <a href="http://wpftoolkit.codeplex.com/wikipage?title=PropertyGrid" rel="nofollow">PropertyGrid</a> that will allow me to edit the <code>IsDirty</code> property through a <code>CheckBox</code> and the <code>Value</code> property through another nested editor.</p>
  
  <p>With help I found <a href="http://doc.xceedsoft.com/products/XceedWpfToolkit/Xceed.Wpf.Toolkit~Xceed.Wpf.Toolkit.PropertyGrid.Editors.ITypeEditor.html" rel="nofollow">here</a> I've got this far:</p>
  
  <pre><code>class MemberEditor&lt;T, TEditor&gt; : ITypeEditor where TEditor : ITypeEditor
  {
      public FrameworkElement ResolveEditor(PropertyItem propertyItem)
      {
          //var member = propertyItem.Value as Member&lt;T&gt;;
  
          // checkbox for the Member.IsDirty value
          var isDirtyCheckbox = new CheckBox();
          var isDirtyBinding = new Binding("Value.IsDirty");
          isDirtyBinding.Source = propertyItem;
          isDirtyBinding.ValidatesOnDataErrors = true;
          isDirtyBinding.ValidatesOnExceptions = true;
          isDirtyBinding.Mode = BindingMode.TwoWay;
          BindingOperations.SetBinding(isDirtyCheckbox, CheckBox.IsCheckedProperty, isDirtyBinding);
  
          // inner editor            
          var valueEditor = new TextBox();
          var valueBinding = new Binding("Value.Value");
          valueBinding.Source = propertyItem;
          valueBinding.ValidatesOnExceptions = true;
          valueBinding.ValidatesOnDataErrors = true;
          valueBinding.Mode = BindingMode.TwoWay;
          BindingOperations.SetBinding(valueEditor, TextBox.TextProperty, valueBinding);
  
          // compose the editor
          var dockPanel = new DockPanel();
          DockPanel.SetDock(isDirtyCheckbox, Dock.Left);
          dockPanel.Children.Add(isDirtyCheckbox);
          DockPanel.SetDock(valueEditor, Dock.Right);
          dockPanel.Children.Add(valueEditor);
  
          return dockPanel;
      }
  }
  </code></pre>
  
  <p>Now I am looking for a way to replace the TextBox, for something like this:</p>
  
  <pre><code>// ...
  TEditor editorResolver;
  PropertyItem innerPropertyItem;
  // ... magic happens here ...
  FrameworkElement valueEditor = editorResolver.ResolveEditor(innerPropertyItem);
  // ...
  </code></pre>
  
  <p>The main goal is to avoid creating new class for each nested editor type.</p>
  
  <p>Any ideas will be very much appreciated!</p>