Browse Source

PropertyGrid BREAKING CHANGES - renamed CustomTypeEditors to EditorDefinitions. Added ability to add custom editors by declaring a DataTemplate. You can target a Type or a list of PropertyNames.

Example:

        <extToolkit:PropertyGrid>
            <extToolkit:PropertyGrid.EditorDefinitions>
                <extToolkit:EditorDefinition TargetType="{x:Type sys:DateTime}">
                    <extToolkit:EditorDefinition.EditorTemplate>
                        <DataTemplate>
                            <extToolkit:DateTimeUpDown Format="ShortDate" Value="{Binding Value}" />
                        </DataTemplate>
                    </extToolkit:EditorDefinition.EditorTemplate>
                </extToolkit:EditorDefinition>
            </extToolkit:PropertyGrid.EditorDefinitions>
        </extToolkit:PropertyGrid>
pull/1645/head
brianlagunas_cp 15 years ago
parent
commit
2523b237d2
  1. 7
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/EditorDefinition.cs
  2. 7
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/EditorDefinitionCollection.cs
  3. 5
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/Editors/DecimalUpDownEditor.cs
  4. 5
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/Editors/DoubleUpDownEditor.cs
  5. 12
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/Editors/ICustomTypeEditor.cs
  6. 4
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/Editors/IntegerUpDownEditor.cs
  7. 13
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/IEditorDefinition.cs
  8. 171
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/PropertyGrid.cs
  9. 20
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/PropertyItem.cs
  10. 8
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/PropertyItemCollection.cs
  11. 8
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/WPFToolkit.Extended.csproj

7
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/Editors/CustomTypeEditor.cs → ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/EditorDefinition.cs

@ -1,11 +1,12 @@
using System.Collections.Generic;
using System;
using System.Windows;
namespace Microsoft.Windows.Controls.PropertyGrid.Editors
namespace Microsoft.Windows.Controls.PropertyGrid
{
public class CustomTypeEditor : ICustomTypeEditor
public class EditorDefinition : IEditorDefinition
{
public ITypeEditor Editor { get; set; }
public DataTemplate EditorTemplate { get; set; }
private IList<string> _properties = new List<string>();
public IList<string> Properties

7
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/CustomTypeEditorCollection.cs → ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/EditorDefinitionCollection.cs

@ -1,12 +1,11 @@
using System;
using System.Collections.ObjectModel;
using Microsoft.Windows.Controls.PropertyGrid.Editors;
namespace Microsoft.Windows.Controls.PropertyGrid
{
public class CustomTypeEditorCollection : ObservableCollection<ICustomTypeEditor>
public class EditorDefinitionCollection : ObservableCollection<IEditorDefinition>
{
public ICustomTypeEditor this[string propertyName]
public IEditorDefinition this[string propertyName]
{
get
{
@ -20,7 +19,7 @@ namespace Microsoft.Windows.Controls.PropertyGrid
}
}
public ICustomTypeEditor this[Type targetType]
public IEditorDefinition this[Type targetType]
{
get
{

5
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/Editors/DecimalUpDownEditor.cs

@ -4,6 +4,11 @@ namespace Microsoft.Windows.Controls.PropertyGrid.Editors
{
public class DecimalUpDownEditor : TypeEditor<DecimalUpDown>
{
protected override void SetControlProperties()
{
Editor.BorderThickness = new System.Windows.Thickness(0);
}
protected override void SetValueDependencyProperty()
{
ValueProperty = DecimalUpDown.ValueProperty;

5
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/Editors/DoubleUpDownEditor.cs

@ -4,6 +4,11 @@ namespace Microsoft.Windows.Controls.PropertyGrid.Editors
{
public class DoubleUpDownEditor : TypeEditor<DoubleUpDown>
{
protected override void SetControlProperties()
{
Editor.BorderThickness = new System.Windows.Thickness(0);
}
protected override void SetValueDependencyProperty()
{
ValueProperty = DoubleUpDown.ValueProperty;

12
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/Editors/ICustomTypeEditor.cs

@ -1,12 +0,0 @@
using System;
using System.Collections.Generic;
namespace Microsoft.Windows.Controls.PropertyGrid.Editors
{
public interface ICustomTypeEditor
{
ITypeEditor Editor { get; set; }
IList<string> Properties { get; set; }
Type TargetType { get; set; }
}
}

4
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/Editors/IntegerUpDownEditor.cs

@ -4,6 +4,10 @@ namespace Microsoft.Windows.Controls.PropertyGrid.Editors
{
public class IntegerUpDownEditor : TypeEditor<IntegerUpDown>
{
protected override void SetControlProperties()
{
Editor.BorderThickness = new System.Windows.Thickness(0);
}
protected override void SetValueDependencyProperty()
{
ValueProperty = IntegerUpDown.ValueProperty;

13
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/IEditorDefinition.cs

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Windows;
namespace Microsoft.Windows.Controls.PropertyGrid
{
public interface IEditorDefinition
{
DataTemplate EditorTemplate { get; set; }
IList<string> Properties { get; set; }
Type TargetType { get; set; }
}
}

171
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/PropertyGrid.cs

@ -35,17 +35,6 @@ namespace Microsoft.Windows.Controls.PropertyGrid
#endregion //AdvancedOptionsMenu
#region CustomTypeEditors
public static readonly DependencyProperty CustomTypeEditorsProperty = DependencyProperty.Register("CustomTypeEditors", typeof(CustomTypeEditorCollection), typeof(PropertyGrid), new UIPropertyMetadata(new CustomTypeEditorCollection()));
public CustomTypeEditorCollection CustomTypeEditors
{
get { return (CustomTypeEditorCollection)GetValue(CustomTypeEditorsProperty); }
set { SetValue(CustomTypeEditorsProperty, value); }
}
#endregion //CustomTypeEditors
#region DisplaySummary
public static readonly DependencyProperty DisplaySummaryProperty = DependencyProperty.Register("DisplaySummary", typeof(bool), typeof(PropertyGrid), new UIPropertyMetadata(true));
@ -57,6 +46,17 @@ namespace Microsoft.Windows.Controls.PropertyGrid
#endregion //DisplaySummary
#region EditorDefinitions
public static readonly DependencyProperty EditorDefinitionsProperty = DependencyProperty.Register("EditorDefinitions", typeof(EditorDefinitionCollection), typeof(PropertyGrid), new UIPropertyMetadata(new EditorDefinitionCollection()));
public EditorDefinitionCollection EditorDefinitions
{
get { return (EditorDefinitionCollection)GetValue(EditorDefinitionsProperty); }
set { SetValue(EditorDefinitionsProperty, value); }
}
#endregion //EditorDefinitions
#region Filter
public static readonly DependencyProperty FilterProperty = DependencyProperty.Register("Filter", typeof(string), typeof(PropertyGrid), new UIPropertyMetadata(null, OnFilterChanged));
@ -117,10 +117,10 @@ namespace Microsoft.Windows.Controls.PropertyGrid
#region Properties
public static readonly DependencyProperty PropertiesProperty = DependencyProperty.Register("Properties", typeof(PropertyCollection), typeof(PropertyGrid), new UIPropertyMetadata(null));
public PropertyCollection Properties
public static readonly DependencyProperty PropertiesProperty = DependencyProperty.Register("Properties", typeof(PropertyItemCollection), typeof(PropertyGrid), new UIPropertyMetadata(null));
public PropertyItemCollection Properties
{
get { return (PropertyCollection)GetValue(PropertiesProperty); }
get { return (PropertyItemCollection)GetValue(PropertiesProperty); }
private set { SetValue(PropertiesProperty, value); }
}
@ -406,77 +406,14 @@ namespace Microsoft.Windows.Controls.PropertyGrid
};
propertyItem.SetBinding(PropertyItem.ValueProperty, binding);
ITypeEditor editor = GetTypeEditor(propertyItem);
propertyItem.Editor = editor.ResolveEditor(propertyItem);
propertyItem.Editor = GetTypeEditor(propertyItem);
return propertyItem;
}
private static PropertyCollection GetCategorizedProperties(List<PropertyItem> propertyItems)
{
PropertyCollection propertyCollection = new PropertyCollection(propertyItems);
propertyCollection.GroupBy("Category");
propertyCollection.SortBy("Category", ListSortDirection.Ascending);
propertyCollection.SortBy("Name", ListSortDirection.Ascending);
return propertyCollection;
}
private static PropertyCollection GetAlphabetizedProperties(List<PropertyItem> propertyItems)
{
PropertyCollection propertyCollection = new PropertyCollection(propertyItems);
propertyCollection.SortBy("Name", ListSortDirection.Ascending);
return propertyCollection;
}
private void SetSelectedObjectNameBinding(object selectedObject)
{
if (selectedObject is FrameworkElement)
{
var binding = new Binding("Name");
binding.Source = selectedObject;
binding.Mode = BindingMode.OneWay;
BindingOperations.SetBinding(this, PropertyGrid.SelectedObjectNameProperty, binding);
}
}
private void SetDragThumbMargin(bool isCategorized)
{
if (_dragThumb == null)
return;
if (isCategorized)
_dragThumb.Margin = new Thickness(6, 0, 0, 0);
else
_dragThumb.Margin = new Thickness(-1, 0, 0, 0);
}
private void ResetPropertyGrid()
{
SelectedObjectName = String.Empty;
SelectedObjectType = null;
_propertyItemsCache = null;
Properties = null;
}
/// <summary>
/// Updates all property values in the PropertyGrid with the data from the SelectedObject
/// </summary>
public void Update()
private FrameworkElement GetTypeEditor(PropertyItem propertyItem)
{
foreach (var item in Properties)
{
BindingOperations.GetBindingExpressionBase(item, PropertyItem.ValueProperty).UpdateTarget();
}
}
#endregion //Methods
private ITypeEditor GetTypeEditor(PropertyItem propertyItem)
{
ITypeEditor editor = null;
editor = CreateCustomEditor(propertyItem, CustomTypeEditors);
FrameworkElement editor = GetCustomEditor(propertyItem, EditorDefinitions);
if (editor == null)
editor = CreateDefaultEditor(propertyItem);
@ -484,15 +421,15 @@ namespace Microsoft.Windows.Controls.PropertyGrid
return editor;
}
private ITypeEditor CreateCustomEditor(PropertyItem propertyItem, CustomTypeEditorCollection customTypeEditors)
private FrameworkElement GetCustomEditor(PropertyItem propertyItem, EditorDefinitionCollection customTypeEditors)
{
ITypeEditor editor = null;
FrameworkElement editor = null;
//check for custom editor
if (customTypeEditors.Count > 0)
{
//first check if the custom editor is type based
ICustomTypeEditor customEditor = customTypeEditors[propertyItem.PropertyType];
IEditorDefinition customEditor = customTypeEditors[propertyItem.PropertyType];
if (customEditor == null)
{
//must be property based
@ -500,13 +437,16 @@ namespace Microsoft.Windows.Controls.PropertyGrid
}
if (customEditor != null)
editor = customEditor.Editor;
{
if (customEditor.EditorTemplate != null)
editor = customEditor.EditorTemplate.LoadContent() as FrameworkElement;
}
}
return editor;
}
private ITypeEditor CreateDefaultEditor(PropertyItem propertyItem)
private FrameworkElement CreateDefaultEditor(PropertyItem propertyItem)
{
ITypeEditor editor = null;
@ -544,7 +484,66 @@ namespace Microsoft.Windows.Controls.PropertyGrid
else
editor = new TextBoxEditor();
return editor;
return editor.ResolveEditor(propertyItem);
}
private static PropertyItemCollection GetCategorizedProperties(List<PropertyItem> propertyItems)
{
PropertyItemCollection propertyCollection = new PropertyItemCollection(propertyItems);
propertyCollection.GroupBy("Category");
propertyCollection.SortBy("Category", ListSortDirection.Ascending);
propertyCollection.SortBy("Name", ListSortDirection.Ascending);
return propertyCollection;
}
private static PropertyItemCollection GetAlphabetizedProperties(List<PropertyItem> propertyItems)
{
PropertyItemCollection propertyCollection = new PropertyItemCollection(propertyItems);
propertyCollection.SortBy("Name", ListSortDirection.Ascending);
return propertyCollection;
}
private void SetSelectedObjectNameBinding(object selectedObject)
{
if (selectedObject is FrameworkElement)
{
var binding = new Binding("Name");
binding.Source = selectedObject;
binding.Mode = BindingMode.OneWay;
BindingOperations.SetBinding(this, PropertyGrid.SelectedObjectNameProperty, binding);
}
}
private void SetDragThumbMargin(bool isCategorized)
{
if (_dragThumb == null)
return;
if (isCategorized)
_dragThumb.Margin = new Thickness(6, 0, 0, 0);
else
_dragThumb.Margin = new Thickness(-1, 0, 0, 0);
}
private void ResetPropertyGrid()
{
SelectedObjectName = String.Empty;
SelectedObjectType = null;
_propertyItemsCache = null;
Properties = null;
}
/// <summary>
/// Updates all property values in the PropertyGrid with the data from the SelectedObject
/// </summary>
public void Update()
{
foreach (var item in Properties)
{
BindingOperations.GetBindingExpressionBase(item, PropertyItem.ValueProperty).UpdateTarget();
}
}
#endregion //Methods
}
}

20
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/PropertyItem.cs

@ -41,19 +41,35 @@ namespace Microsoft.Windows.Controls.PropertyGrid
{
get { return (string)GetValue(DisplayNameProperty); }
set { SetValue(DisplayNameProperty, value); }
}
}
#endregion //DisplayName
#region Editor
public static readonly DependencyProperty EditorProperty = DependencyProperty.Register("Editor", typeof(FrameworkElement), typeof(PropertyItem), new UIPropertyMetadata(null));
public static readonly DependencyProperty EditorProperty = DependencyProperty.Register("Editor", typeof(FrameworkElement), typeof(PropertyItem), new UIPropertyMetadata(null, OnEditorChanged));
public FrameworkElement Editor
{
get { return (FrameworkElement)GetValue(EditorProperty); }
set { SetValue(EditorProperty, value); }
}
private static void OnEditorChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
{
PropertyItem propertyItem = o as PropertyItem;
if (propertyItem != null)
propertyItem.OnEditorChanged((FrameworkElement)e.OldValue, (FrameworkElement)e.NewValue);
}
protected virtual void OnEditorChanged(FrameworkElement oldValue, FrameworkElement newValue)
{
if (oldValue != null)
oldValue.DataContext = null;
if (newValue != null)
newValue.DataContext = this;
}
#endregion //Editor
private object _instance;

8
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/PropertyCollection.cs → ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/PropertyItemCollection.cs

@ -6,19 +6,19 @@ using System.Windows.Data;
namespace Microsoft.Windows.Controls.PropertyGrid
{
public class PropertyCollection : ObservableCollection<PropertyItem>
public class PropertyItemCollection : ObservableCollection<PropertyItem>
{
public PropertyCollection()
public PropertyItemCollection()
{
}
public PropertyCollection(List<PropertyItem> list)
public PropertyItemCollection(List<PropertyItem> list)
: base(list)
{
}
public PropertyCollection(IEnumerable<PropertyItem> collection)
public PropertyItemCollection(IEnumerable<PropertyItem> collection)
: base(collection)
{

8
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/WPFToolkit.Extended.csproj

@ -249,14 +249,14 @@
</Compile>
<Compile Include="PropertyGrid\Implementation\Editors\ColorEditor.cs" />
<Compile Include="PropertyGrid\Implementation\Editors\ComboBoxEditor.cs" />
<Compile Include="PropertyGrid\Implementation\Editors\CustomTypeEditor.cs" />
<Compile Include="PropertyGrid\Implementation\CustomTypeEditorCollection.cs" />
<Compile Include="PropertyGrid\Implementation\EditorDefinition.cs" />
<Compile Include="PropertyGrid\Implementation\EditorDefinitionCollection.cs" />
<Compile Include="PropertyGrid\Implementation\Editors\DateTimeUpDownEditor.cs" />
<Compile Include="PropertyGrid\Implementation\Editors\DecimalUpDownEditor.cs" />
<Compile Include="PropertyGrid\Implementation\Editors\DoubleUpDownEditor.cs" />
<Compile Include="PropertyGrid\Implementation\Editors\EnumComboBoxEditor.cs" />
<Compile Include="PropertyGrid\Implementation\Editors\FontComboBoxEditor.cs" />
<Compile Include="PropertyGrid\Implementation\Editors\ICustomTypeEditor.cs" />
<Compile Include="PropertyGrid\Implementation\IEditorDefinition.cs" />
<Compile Include="PropertyGrid\Implementation\Editors\IntegerUpDownEditor.cs" />
<Compile Include="PropertyGrid\Implementation\Editors\ITypeEditor.cs" />
<Compile Include="PropertyGrid\Implementation\Editors\PrimitiveTypeCollectionEditor.cs" />
@ -264,7 +264,7 @@
<Compile Include="PropertyGrid\Implementation\Editors\TextBoxEditor.cs" />
<Compile Include="PropertyGrid\Implementation\Editors\TypeEditor.cs" />
<Compile Include="PropertyGrid\Implementation\PropertyGrid.cs" />
<Compile Include="PropertyGrid\Implementation\PropertyCollection.cs" />
<Compile Include="PropertyGrid\Implementation\PropertyItemCollection.cs" />
<Compile Include="PropertyGrid\Implementation\PropertyItem.cs" />
<Compile Include="PropertyGrid\Implementation\Commands\PropertyItemCommands.cs" />
<Compile Include="RichTextBoxFormatBar\IRichTextBoxFormatBar.cs" />

Loading…
Cancel
Save