0

I am new to WPF, and I am using xceed property grid, in my class i have a custom collection editor. As per xceed, I found that I have to implement "Xceed.Wpf.Toolkit.PropertyGrid.Editors.ITypeEditor", I have implemented it, but I get error when trying to set binding. Error message: 'Two-way binding requires Path or XPath'. Below is the c# class, where property is defined:

 /// <summary>
/// The expected assembly versions.
/// </summary>
[DescriptionAttribute("The expected assembly versions.")]
[Category("Mandatory")]
[ExpandableObject]
[Editor(typeof(Assembly), typeof(Assembly))]
public Assembly[] ExpectedAssemblyVersions
{
  get;
  set;
}
   /// <summary>
/// To verify assembly and there versions
/// </summary>
[TypeConverterAttribute(typeof(ExpandableObjectConverter))]
public class Assembly : Xceed.Wpf.Toolkit.PropertyGrid.Editors.ITypeEditor
{
  /// <summary>
  /// Assembly Name
  /// </summary>
  public string Name { get; set; }
  /// <summary>
  /// Assembly versions
  /// </summary>
  public string[] Versions { get; set; }

  #region Implementation of ITypeEditor
  /// <summary>
  /// 
  /// </summary>
  /// <param name="propertyItem"></param>
  /// <returns></returns>
  public FrameworkElement ResolveEditor(PropertyItem propertyItem)
  {
    TextBox textBox = new TextBox();
    var _binding = new Binding(Name);
    _binding.Source = propertyItem;
    _binding.ValidatesOnExceptions = true;
    _binding.ValidatesOnDataErrors = true;
    _binding.Mode = propertyItem.IsReadOnly ? BindingMode.OneWay : BindingMode.TwoWay;
    BindingOperations.SetBinding(textBox, TextBox.TextProperty, _binding);
    return textBox;
  }
  #endregion
}

Xaml binding:

<xctk:PropertyGrid Name="pk" Foreground="{Binding SelectedTheme.FontShade}" HorizontalAlignment="Stretch"  VerticalAlignment="Stretch" FontWeight="ExtraBold"  Background="{Binding SelectedTheme.DarkShade}" SelectedObject="{Binding SelectedElement,UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"/>

the implementation of 'ResolveEditor' is not complete, I need help in fixing this.

Sanjoth
  • 13
  • 1
  • 5
  • Where do you set the value of the ``Name`` property that is used for the ``Binding`` constructor? – Oliver Jun 23 '15 at 12:27
  • My implementation of ResolveEditor is not correct, may be u can guide me in getting it right. EndResult:In the property grid, parameter 'ExpectedAssemblyVersions' is displayed, if i click on this, collection editor will be opened, where i have to add name & version and click Ok button. On click of ok button, I get an Object reference not set to an instance of an object, ' at Xceed.Wpf.Toolkit.CollectionControl.CreateItemsSource() at Xceed.Wpf.Toolkit.CollectionControl.ComputeItemsSource() at Xceed.Wpf.Toolkit.CollectionControl.PersistChanges()'. – Sanjoth Jun 24 '15 at 08:22

1 Answers1

2

Do you mean something like this:

class Properties
{
    private List<Assembly> assemblies = new List<Assembly>();

    [DisplayName("ExpectedAssemblyVersions")]
    [Description("The expected assembly versions.")]
    [Category("Mandatory")]
    [Editor(typeof(CollectionEditor), typeof(CollectionEditor))]
    public List<Assembly> Assemblies
    {
        get
        {
            return assemblies;
        }
        set
        {
            assemblies = value;
        }
    }
}

class Assembly
{
    public string Name { get; set; }

    public string Version { get; set; }
}
Oliver
  • 1,507
  • 1
  • 12
  • 23