Xceed Toolkit Plus for WPF v5.0 Documentation
Xceed.Wpf.Toolkit Assembly / Xceed.Wpf.Toolkit.PropertyGrid.Editors Namespace / ITypeEditor Interface
Members 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 
    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.
    //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;
            }
        }
    The following is the XAML for a UserControl-based custom editor.
    <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>
    The following is the code behind for a UserControl-based custom editor.
    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;
            }
        }
    The following shows an example of how to use the custom class and UserControl.
    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; }
            }
    Requirements

    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

    See Also