From d34bf44016ff8a8e36fabe6c12fc3092c8f5899c Mon Sep 17 00:00:00 2001 From: brianlagunas_cp Date: Sun, 13 Mar 2011 16:02:52 +0000 Subject: [PATCH] PropertyGrid: custom type editors can now target specific properties or a particular type. --- .../Implementation/CustomTypeEditorCollection.cs | 14 ++++++++++++++ .../Implementation/Editors/CustomTypeEditor.cs | 3 +++ .../Implementation/Editors/ICustomTypeEditor.cs | 1 + .../PropertyGrid/Implementation/PropertyGrid.cs | 11 ++++++++--- 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/CustomTypeEditorCollection.cs b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/CustomTypeEditorCollection.cs index d8cfc800..585ba312 100644 --- a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/CustomTypeEditorCollection.cs +++ b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/CustomTypeEditorCollection.cs @@ -19,5 +19,19 @@ namespace Microsoft.Windows.Controls.PropertyGrid return null; } } + + public ICustomTypeEditor this[Type targetType] + { + get + { + foreach (var item in Items) + { + if (item.TargetType == targetType) + return item; + } + + return null; + } + } } } diff --git a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/Editors/CustomTypeEditor.cs b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/Editors/CustomTypeEditor.cs index 3e617091..36ac5730 100644 --- a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/Editors/CustomTypeEditor.cs +++ b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/Editors/CustomTypeEditor.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System; namespace Microsoft.Windows.Controls.PropertyGrid.Editors { @@ -12,5 +13,7 @@ namespace Microsoft.Windows.Controls.PropertyGrid.Editors get { return _properties; } set { _properties = value; } } + + public Type TargetType { get; set; } } } diff --git a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/Editors/ICustomTypeEditor.cs b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/Editors/ICustomTypeEditor.cs index ee0019fd..241d944c 100644 --- a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/Editors/ICustomTypeEditor.cs +++ b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/Editors/ICustomTypeEditor.cs @@ -7,5 +7,6 @@ namespace Microsoft.Windows.Controls.PropertyGrid.Editors { ITypeEditor Editor { get; set; } IList Properties { get; set; } + Type TargetType { get; set; } } } diff --git a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/PropertyGrid.cs b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/PropertyGrid.cs index 1fb2e6d7..a8ab1551 100644 --- a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/PropertyGrid.cs +++ b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/PropertyGrid.cs @@ -266,11 +266,16 @@ namespace Microsoft.Windows.Controls.PropertyGrid //check for custom editor if (CustomTypeEditors.Count > 0) { - ICustomTypeEditor customEditor = CustomTypeEditors[propertyItem.Name]; - if (customEditor != null) + //first check if the custom editor is type based + ICustomTypeEditor customEditor = CustomTypeEditors[propertyItem.PropertyType]; + if (customEditor == null) { - editor = customEditor.Editor; + //must be property based + customEditor = CustomTypeEditors[propertyItem.Name]; } + + if (customEditor != null) + editor = customEditor.Editor; } //no custom editor found