Browse Source

PropertyGrid: added new property called AutoGenerateProperties. When true it will autogenerate all properties for an object. Wehn set to false if till not generate any properties, but instead you supply the property to show be defining PropertyDefinitions. here is an example:

<extToolkit:PropertyGrid AutoGenerateProperties="False">
            <extToolkit:PropertyGrid.PropertyDefinitions>
                <extToolkit:PropertyDefinition Name="FirstName" />
                <extToolkit:PropertyDefinition Name="Age" />
            </extToolkit:PropertyGrid.PropertyDefinitions>
        </extToolkit:PropertyGrid>

This will only show the FirstName and Age properties of the bound object.
pull/1645/head
brianlagunas_cp 15 years ago
parent
commit
50f76f0649
  1. 7
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/EditorDefinition.cs
  2. 3
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/EditorDefinitionCollection.cs
  3. 3
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/IEditorDefinition.cs
  4. 9
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/PropertyDefinition.cs
  5. 21
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/PropertyDefinitionCollection.cs
  6. 55
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/PropertyGrid.cs
  7. 2
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/WPFToolkit.Extended.csproj

7
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/EditorDefinition.cs

@ -1,5 +1,4 @@
using System.Collections.Generic;
using System;
using System;
using System.Windows;
namespace Microsoft.Windows.Controls.PropertyGrid
@ -8,8 +7,8 @@ namespace Microsoft.Windows.Controls.PropertyGrid
{
public DataTemplate EditorTemplate { get; set; }
private List<string> _properties = new List<string>();
public List<string> Properties
private PropertyDefinitionCollection _properties = new PropertyDefinitionCollection();
public PropertyDefinitionCollection PropertiesDefinitions
{
get { return _properties; }
set { _properties = value; }

3
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/EditorDefinitionCollection.cs

@ -1,4 +1,5 @@
using System;
using System.Linq;
using System.Collections.ObjectModel;
namespace Microsoft.Windows.Controls.PropertyGrid
@ -11,7 +12,7 @@ namespace Microsoft.Windows.Controls.PropertyGrid
{
foreach (var item in Items)
{
if (item.Properties.Contains(propertyName))
if (item.PropertiesDefinitions.Where(x => x.Name == propertyName).Any())
return item;
}

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

@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Windows;
namespace Microsoft.Windows.Controls.PropertyGrid
@ -7,7 +6,7 @@ namespace Microsoft.Windows.Controls.PropertyGrid
public interface IEditorDefinition
{
DataTemplate EditorTemplate { get; set; }
List<string> Properties { get; set; }
PropertyDefinitionCollection PropertiesDefinitions { get; set; }
Type TargetType { get; set; }
}
}

9
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/PropertyDefinition.cs

@ -0,0 +1,9 @@
using System;
namespace Microsoft.Windows.Controls.PropertyGrid
{
public class PropertyDefinition
{
public string Name { get; set; }
}
}

21
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/PropertyDefinitionCollection.cs

@ -0,0 +1,21 @@
using System.Collections.ObjectModel;
namespace Microsoft.Windows.Controls.PropertyGrid
{
public class PropertyDefinitionCollection : ObservableCollection<PropertyDefinition>
{
public PropertyDefinition this[string propertyName]
{
get
{
foreach (var item in Items)
{
if (item.Name == propertyName)
return item;
}
return null;
}
}
}
}

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

@ -8,6 +8,7 @@ using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Input;
using Microsoft.Windows.Controls.PropertyGrid.Commands;
using System.Reflection;
namespace Microsoft.Windows.Controls.PropertyGrid
{
@ -33,6 +34,17 @@ namespace Microsoft.Windows.Controls.PropertyGrid
#endregion //AdvancedOptionsMenu
#region AutoGenerateProperties
public static readonly DependencyProperty AutoGeneratePropertiesProperty = DependencyProperty.Register("AutoGenerateProperties", typeof(bool), typeof(PropertyGrid), new UIPropertyMetadata(true));
public bool AutoGenerateProperties
{
get { return (bool)GetValue(AutoGeneratePropertiesProperty); }
set { SetValue(AutoGeneratePropertiesProperty, value); }
}
#endregion //AutoGenerateProperties
#region DisplaySummary
public static readonly DependencyProperty DisplaySummaryProperty = DependencyProperty.Register("DisplaySummary", typeof(bool), typeof(PropertyGrid), new UIPropertyMetadata(true));
@ -46,7 +58,7 @@ namespace Microsoft.Windows.Controls.PropertyGrid
#region EditorDefinitions
public static readonly DependencyProperty EditorDefinitionsProperty = DependencyProperty.Register("EditorDefinitions", typeof(EditorDefinitionCollection), typeof(PropertyGrid), new UIPropertyMetadata(new EditorDefinitionCollection()));
public static readonly DependencyProperty EditorDefinitionsProperty = DependencyProperty.Register("EditorDefinitions", typeof(EditorDefinitionCollection), typeof(PropertyGrid), new UIPropertyMetadata(null));
public EditorDefinitionCollection EditorDefinitions
{
get { return (EditorDefinitionCollection)GetValue(EditorDefinitionsProperty); }
@ -124,6 +136,17 @@ namespace Microsoft.Windows.Controls.PropertyGrid
#endregion //Properties
#region PropertyDefinitions
public static readonly DependencyProperty PropertyDefinitionsProperty = DependencyProperty.Register("PropertyDefinitions", typeof(PropertyDefinitionCollection), typeof(PropertyGrid), new UIPropertyMetadata(null));
public PropertyDefinitionCollection PropertyDefinitions
{
get { return (PropertyDefinitionCollection)GetValue(PropertyDefinitionsProperty); }
set { SetValue(PropertyDefinitionsProperty, value); }
}
#endregion //PropertyDefinitions
#region SelectedObject
public static readonly DependencyProperty SelectedObjectProperty = DependencyProperty.Register("SelectedObject", typeof(object), typeof(PropertyGrid), new UIPropertyMetadata(null, OnSelectedObjectChanged));
@ -275,6 +298,8 @@ namespace Microsoft.Windows.Controls.PropertyGrid
public PropertyGrid()
{
EditorDefinitions = new EditorDefinitionCollection();
PropertyDefinitions = new PropertyDefinitionCollection();
CommandBindings.Add(new CommandBinding(PropertyGridCommands.ClearFilter, ClearFilter, CanClearFilter));
}
@ -286,8 +311,11 @@ namespace Microsoft.Windows.Controls.PropertyGrid
{
base.OnApplyTemplate();
_dragThumb = (Thumb)GetTemplateChild("PART_DragThumb");
_dragThumb.DragDelta += DragThumb_DragDelta;
if (_dragThumb != null)
_dragThumb.DragDelta -= DragThumb_DragDelta;
_dragThumb = GetTemplateChild("PART_DragThumb") as Thumb;
if (_dragThumb != null)
_dragThumb.DragDelta += DragThumb_DragDelta;
}
protected override void OnPreviewKeyDown(KeyEventArgs e)
@ -355,7 +383,26 @@ namespace Microsoft.Windows.Controls.PropertyGrid
try
{
var descriptors = PropertyGridUtilities.GetPropertyDescriptors(instance);
PropertyDescriptorCollection descriptors = PropertyGridUtilities.GetPropertyDescriptors(instance);
if (!AutoGenerateProperties)
{
List<PropertyDescriptor> specificProperties = new List<PropertyDescriptor>();
foreach (PropertyDefinition pd in PropertyDefinitions)
{
foreach (PropertyDescriptor descriptor in descriptors)
{
if (descriptor.Name == pd.Name)
{
specificProperties.Add(descriptor);
break;
}
}
}
descriptors = new PropertyDescriptorCollection(specificProperties.ToArray());
}
foreach (PropertyDescriptor descriptor in descriptors)
{
if (descriptor.IsBrowsable)

2
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/WPFToolkit.Extended.csproj

@ -268,6 +268,8 @@
<Compile Include="PropertyGrid\Implementation\Editors\TextBoxEditor.cs" />
<Compile Include="PropertyGrid\Implementation\Editors\TypeEditor.cs" />
<Compile Include="Core\Converters\ExpandableObjectMarginConverter.cs" />
<Compile Include="PropertyGrid\Implementation\PropertyDefinition.cs" />
<Compile Include="PropertyGrid\Implementation\PropertyDefinitionCollection.cs" />
<Compile Include="PropertyGrid\Implementation\PropertyGrid.cs" />
<Compile Include="PropertyGrid\Implementation\PropertyItemCollection.cs" />
<Compile Include="PropertyGrid\Implementation\PropertyItem.cs" />

Loading…
Cancel
Save