'Declaration Public Interface ITypeEditor
'Usage Dim instance As ITypeEditor
public interface ITypeEditor
'Declaration Public Interface ITypeEditor
'Usage Dim instance As ITypeEditor
public interface ITypeEditor
//Custom editors that are used as attributes MUST implement the ITypeEditor interface. public class FirstNameEditor : Xceed.Wpf.Toolkit.PropertyGrid.Editors.ITypeEditor { public FrameworkElement ResolveEditor(Xceed.Wpf.Toolkit.PropertyGrid.PropertyItem propertyItem) { TextBox textBox = new TextBox(); textBox.Background = new SolidColorBrush(Colors.Red); //create the binding from the bound property item to the editor var _binding = new Binding("Value"); //bind to the Value property of the PropertyItem _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; } }
<UserControl x:Class="Samples.Modules.PropertyGrid.LastNameUserControlEditor" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Name="_uc"> <StackPanel> <TextBox Text="{Binding Value, ElementName=_uc}" Background="YellowGreen" /> <Button Click="Button_Click">Clear</Button> </StackPanel> </UserControl>
public partial class LastNameUserControlEditor : UserControl, ITypeEditor { public LastNameUserControlEditor() { InitializeComponent(); } public static readonly DependencyProperty ValueProperty = DependencyProperty.Register("Value", typeof(string), typeof(LastNameUserControlEditor), new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault)); public string Value { get { return (string)GetValue(ValueProperty); } set { SetValue(ValueProperty, value); } } private void Button_Click(object sender, RoutedEventArgs e) { Value = string.Empty; } public FrameworkElement ResolveEditor(Xceed.Wpf.Toolkit.PropertyGrid.PropertyItem propertyItem) { Binding binding = new Binding("Value"); binding.Source = propertyItem; binding.Mode = propertyItem.IsReadOnly ? BindingMode.OneWay : BindingMode.TwoWay; BindingOperations.SetBinding(this, LastNameUserControlEditor.ValueProperty, binding); return this; } }
public class CustomAttributEditorPerson { [Category("Information")] [DisplayName("First Name")] [Description("This property uses a TextBox as the default editor.")] //This custom editor is a Class that implements the ITypeEditor interface [Editor(typeof(FirstNameEditor), typeof(FirstNameEditor))] public string FirstName { get; set; } [Category("Information")] [DisplayName("Last Name")] [Description("This property uses a TextBox as the default editor.")] //This custom editor is a UserControl that implements the ITypeEditor interface [Editor(typeof(LastNameUserControlEditor), typeof(LastNameUserControlEditor))] public string LastName { get; set; } }
Target Platforms: Windows 11, Windows 10, Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2