[英]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.