'DeclarationPublic Interface ITypeEditor
'UsageDim instance As ITypeEditor
public interface ITypeEditor
'DeclarationPublic Interface ITypeEditor
'UsageDim instance As ITypeEditor
public interface ITypeEditor
| Name | Description | |
|---|---|---|
![]() | ResolveEditor | Resolves the editor of the passed PropertyItem. |
//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; } }
.NET: net5.0, net5.0-windows, net6.0, net6.0-macos, net6.0-windows, net7.0, net7.0-macos, net7.0-windows, net8.0, net8.0-browser, net8.0-macos, net8.0-windows, net9.0, net9.0-browser, net9.0-macos, net9.0-windows, net10.0, net10.0-browser, net10.0-macos, net10.0-windows.
.NET Framework: net40, net403, net45, net451, net452, net46, net461, net462, net463, net47, net471, net472, net48, net481.