私は WPF が初めてで、xceed プロパティ グリッドを使用しています。私のクラスには、カスタム コレクション エディターがあります。xceed によると、「Xceed.Wpf.Toolkit.PropertyGrid.Editors.ITypeEditor」を実装する必要があることがわかりました。実装しましたが、バインディングを設定しようとするとエラーが発生します。エラー メッセージ:「双方向バインディングにはパスまたは 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」の実装は完全ではありません。これを修正するには助けが必要です。