From f39523515da16bec8e2f8576fd6f3ec8aa961b4c Mon Sep 17 00:00:00 2001 From: brianlagunas_cp Date: Thu, 6 Oct 2011 17:03:47 +0000 Subject: [PATCH] PropertyGrid: Deleted custom TypeEditorAttribute for defining editors and instead use the already common EditorAttribute provided my the .NET framework. Editors MUST implement the ITypeEditor interface. So now to declare custom editors you define them as follows: private TimeSpan _timeSpan; [Editor(typeof(MyCustomEditor), typeof(MyCustomEditor))] public TimeSpan TimeSpan { get { return _timeSpan; } set { _timeSpan = value; } } public class MyCustomEditor : ITypeEditor { public FrameworkElement ResolveEditor(PropertyItem propertyItem) { TextBox editor = new TextBox(); Binding binding = new Binding("Value"); //bind to the Value property of the PropertyItem instance binding.Source = propertyItem; binding.Mode = propertyItem.IsWriteable ? BindingMode.TwoWay : BindingMode.OneWay; BindingOperations.SetBinding(editor, TextBox.TextProperty, binding); return editor; } } --- .../Attributes/TypeEditorAttribute.cs | 18 ------------------ .../Implementation/PropertyGrid.cs | 10 ++++++---- .../WPFToolkit.Extended.csproj | 1 - 3 files changed, 6 insertions(+), 23 deletions(-) delete mode 100644 ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/Attributes/TypeEditorAttribute.cs diff --git a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/Attributes/TypeEditorAttribute.cs b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/Attributes/TypeEditorAttribute.cs deleted file mode 100644 index 26bbd28f..00000000 --- a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/Attributes/TypeEditorAttribute.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System; - -namespace Microsoft.Windows.Controls.PropertyGrid.Attributes -{ - public class TypeEditorAttribute : Attribute - { - public Type Type { get; set; } - - public TypeEditorAttribute(Type type) - { - var valueSourceInterface = type.GetInterface("Microsoft.Windows.Controls.PropertyGrid.Editors.ITypeEditor"); - if (valueSourceInterface == null) - throw new ArgumentException("Type must implement the ITypeEditor interface.", "type"); - - Type = type; - } - } -} diff --git a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/PropertyGrid.cs b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/PropertyGrid.cs index 8b0c90b7..b0869610 100644 --- a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/PropertyGrid.cs +++ b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/PropertyGrid.cs @@ -407,7 +407,7 @@ namespace Microsoft.Windows.Controls.PropertyGrid }; propertyItem.SetBinding(PropertyItem.ValueProperty, binding); - propertyItem.Editor = GetTypeEditor(propertyItem); + propertyItem.Editor = GetTypeEditor(propertyItem); return propertyItem; } @@ -436,11 +436,13 @@ namespace Microsoft.Windows.Controls.PropertyGrid if (itemsSourceAttribute != null) editor = new ItemsSourceEditor(itemsSourceAttribute).ResolveEditor(propertyItem); - var editorAttribute = GetAttribute(propertyItem.PropertyDescriptor); + var editorAttribute = GetAttribute(propertyItem.PropertyDescriptor); if (editorAttribute != null) { - var instance = Activator.CreateInstance(editorAttribute.Type); - editor = (instance as ITypeEditor).ResolveEditor(propertyItem); + Type type = Type.GetType(editorAttribute.EditorTypeName); + var instance = Activator.CreateInstance(type); + if (instance is ITypeEditor) + editor = (instance as ITypeEditor).ResolveEditor(propertyItem); } return editor; diff --git a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/WPFToolkit.Extended.csproj b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/WPFToolkit.Extended.csproj index 81859f16..282f6c85 100644 --- a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/WPFToolkit.Extended.csproj +++ b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/WPFToolkit.Extended.csproj @@ -237,7 +237,6 @@ True -