简体   繁体   English

Xceed WPF propertyGrid自定义集合编辑器

[英]Xceed WPF propertyGrid Custom Collection editor

I am new to WPF, and I am using xceed property grid, in my class i have a custom collection editor. 我是WPF的新手,我使用xceed属性网格,在我的课程中,我有一个自定义集合编辑器。 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. 按照xceed,我发现我必须实现“ Xceed.Wpf.Toolkit.PropertyGrid.Editors.ITypeEditor”,但是已经实现了,但是在尝试设置绑定时出现错误。 Error message: 'Two-way binding requires Path or XPath'. 错误消息:“双向绑定需要路径或XPath”。 Below is the c# class, where property is defined: 下面是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 binding: 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}"/>

the implementation of 'ResolveEditor' is not complete, I need help in fixing this. “ ResolveEditor”的实现不完整,我需要帮助解决此问题。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Xceed WPF propertyGrid 显示扩展集合的项目 - Xceed WPF propertyGrid show item for expanded collection Xceed WPF Propertygrid-集合控件:多种类型 - Xceed WPF Propertygrid - Collection Control: Multiple Types WPF Xceed PropertyGrid显示“ Xceed.Wpf.Toolkit.PropertyGrid.Attributes.Item”,而不是实际的DisplayName - WPF Xceed PropertyGrid showing “Xceed.Wpf.Toolkit.PropertyGrid.Attributes.Item” instead of the real DisplayName 如何在PropertyGrid自定义集合编辑器中的“添加”按钮下拉列表中自定义名称 - How to customize names in “Add” button dropdown in the PropertyGrid custom collection editor 自定义主动性属性在PropertyGrid中不显示集合编辑器 - Custom Acivity property does not show Collection Editor in PropertyGrid 如何在Xceed PropertyGrid for WPF中隐藏子属性? - How can you hide a sub-property in the Xceed PropertyGrid for WPF? Xceed.Wpf.Toolkit.PropertyGrid显示属性的子集 - Xceed.Wpf.Toolkit.PropertyGrid show subset of properties Xceed.Wpf.Toolkit.PropertyGrid.PropertyGrid:本地创建的对象属于其他线程吗? - Xceed.Wpf.Toolkit.PropertyGrid.PropertyGrid: Locally created object belongs to a different thread? 如何使用 C# 中的另一个(嵌套)编辑器为扩展 WPF 工具包 PropertyGrid 创建自定义属性编辑器? - How to create a custom property editor for Extended WPF Toolkit PropertyGrid with another (nested) editor in C#? Xceed PropertyGrid中的类别排序 - Category Ordering In Xceed PropertyGrid
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM