Xceed Toolkit Plus for WPF v5.1 Documentation
Xceed.Wpf.Toolkit Assembly / Xceed.Wpf.Toolkit.PropertyGrid.Editors Namespace / ITypeEditor Interface
Example


In This Topic
    ITypeEditor Interface
    In This Topic
    Provides an interface that is implemented by TypeEditor and custom editors classes/controls.
    Syntax
    'Declaration
     
    
    Public Interface ITypeEditor 
    'Usage
     
    
    Dim instance As ITypeEditor
    public interface ITypeEditor 
    Public Methods
     NameDescription
     MethodResolves the editor of the passed PropertyItem.  
    Top
    Remarks
    You can supply editors for a property by using the System.ComponentModel.EditorAttribute. In order to provide an editor with an attribute, the editor must implement the ITypeEditor interface. Your editor can be a simple class or a complex UserControl.
    Example
    The following is an ITypeEditor-derived custom editor class.The following is the XAML for a UserControl-based custom editor.The following is the code behind for a UserControl-based custom editor.The following shows an example of how to use the custom class and UserControl.
    //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; }
            }
    Supported Frameworks

    .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.

    See Also