Good day!
The second day I struggle in studying WPF PropertyGrid from xceed. There is little documentation on it, as well as my knowledge on WPF, but I would like to solve this problem.
Created an object, placed it in a PropertyGrid, implemented its own editor of property fields for an object. Records are displayed in the editor, I successfully select them, but they are not attached to the object property fields.
Test case below.
Property editor
<UserControl x:Class="TestExtendedWPFTools.DropDownControl" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" mc:Ignorable="d" d:DesignHeight="30" d:DesignWidth="300" x:Name="_uc"> <StackPanel> <ComboBox x:Name="cb" Text="{Binding Value, ElementName=_uc}"></ComboBox> </StackPanel> </UserControl> using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using Xceed.Wpf.Toolkit.PropertyGrid.Editors; using Xceed.Wpf.Toolkit.PropertyGrid; namespace TestExtendedWPFTools { /// <summary> /// ΠΠΎΠ³ΠΈΠΊΠ° Π²Π·Π°ΠΈΠΌΠΎΠ΄Π΅ΠΉΡΡΠ²ΠΈΡ Π΄Π»Ρ DropDownControl.xaml /// </summary> public partial class DropDownControl : UserControl, ITypeEditor { public DropDownControl() { InitializeComponent(); for (var i = 0; i < 10; i++) { cb.Items.Add(new Field() { Key = i.ToString(), Value = string.Format("Record: {0}", i), }); } } public static DependencyProperty ValueProperty = DependencyProperty.Register("Value", typeof(Field), typeof(DropDownControl), new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault)); public Field Value { get { return (Field)GetValue(ValueProperty); } set { SetValue(ValueProperty, value); } } public FrameworkElement ResolveEditor(PropertyItem propertyItem) { var binding = new Binding("Value"); binding.Source = propertyItem; binding.Mode = propertyItem.IsReadOnly ? BindingMode.OneWay : BindingMode.TwoWay; BindingOperations.SetBinding(this, DropDownControl.ValueProperty, binding); return this; } } } Editable object
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.ComponentModel; namespace TestExtendedWPFTools { public class DBInfo { [Editor(typeof(DropDownControl), typeof(DropDownControl))] public Field Access { get; set; } } } using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace TestExtendedWPFTools { public class Field { public string Key { get; set; } public string Value { get; set; } //public override string ToString() //{ // return Value; //} } } Just in case, the main window of the program
<Window x:Class="TestExtendedWPFTools.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:xc="clr-namespace:Xceed.Wpf.Toolkit.PropertyGrid;assembly=Xceed.Wpf.Toolkit" Title="MainWindow" Height="350" Width="525"> <Grid> <Grid.RowDefinitions> <RowDefinition Height="auto"></RowDefinition> <RowDefinition></RowDefinition> </Grid.RowDefinitions> <Button Width="200" Height="32" Click="Button_Click">Π’Π΅ΡΡΠΎΠ²Π°Ρ ΠΊΠ½ΠΎΠΏΠΊΠ°</Button> <xc:PropertyGrid x:Name="grid" Grid.Row="1" AutoGenerateProperties="True" ShowSearchBox="False"> </xc:PropertyGrid> </Grid> </Window> /// ΠΠΎΠ³ΠΈΠΊΠ° Π²Π·Π°ΠΈΠΌΠΎΠ΄Π΅ΠΉΡΡΠ²ΠΈΡ Π΄Π»Ρ MainWindow.xaml /// </summary> public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); dbinfo = new DBInfo(); grid.SelectedObject = dbinfo; } public DBInfo dbinfo { get; set; } private void Button_Click(object sender, RoutedEventArgs e) { if (dbinfo != null) { } } } }