首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Xceed WPF propertyGrid自定义集合编辑器

Xceed WPF propertyGrid自定义集合编辑器
EN

Stack Overflow用户
提问于 2015-06-23 11:57:32
回答 1查看 4.8K关注 0票数 0

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

代码语言:javascript
运行
复制
 /// <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绑定:

代码语言:javascript
运行
复制
<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”的实现还没有完成,我需要帮助解决这个问题。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-06-24 10:56:11

你的意思是这样的:

代码语言:javascript
运行
复制
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; }
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31002154

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档