【问题标题】:Xceed WPF propertyGrid Custom Collection editorXceed WPF propertyGrid 自定义集合编辑器
【发布时间】:2015-06-23 11:57:32
【问题描述】:

我是 WPF 新手,我正在使用 xceed 属性网格,在我的课堂上我有一个自定义集合编辑器。根据 xceed,我发现我必须实现“Xceed.Wpf.Toolkit.PropertyGrid.Editors.ITypeEditor”,我已经实现了它,但是在尝试设置绑定时出现错误。错误消息:“双向绑定需要 Path 或 XPath”。下面是 c# 类,其中定义了属性:

 /// <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 绑定:

<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}"/>

“ResolveEditor”的实现不完整,我需要帮助来解决这个问题。

【问题讨论】:

  • 在哪里设置用于Binding 构造函数的Name 属性的值?
  • 我的 ResolveEditor 实现不正确,也许你能指导我把它弄好。 EndResult:在属性网格中,显示参数“ExpectedAssemblyVersions”,如果我单击它,将打开集合编辑器,我必须在其中添加名称和版本,然后单击确定按钮。单击确定按钮时,我在 Xceed.Wpf.Toolkit.CollectionControl.ComputeItemsSource() 处的 Xceed.Wpf.Toolkit.CollectionControl.CreateItemsSource() 处获得未设置为对象实例的对象引用。 Toolkit.CollectionControl.PersistChanges()'.

标签: c# wpf xaml propertygrid xceed


【解决方案1】:

你的意思是这样的:

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; }
}

【讨论】:

  • 我试过你的代码,它有效。非常感谢。干杯:)
猜你喜欢
  • 1970-01-01
  • 2018-10-30
  • 1970-01-01
  • 2016-07-17
  • 2013-03-25
  • 2011-05-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多