Browse Source

PropertyGrid: implemented PropertyOrderAttribute. You can now apply the PropertyOrder attirbute to a property to control the order in which the properties are sorted. The attribute is only honored while in the Categorized view and ignored when sorted alphabetically

pull/1645/head
brianlagunas_cp 14 years ago
parent
commit
3f9a4d19f1
  1. 15
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/Attributes/PropertyOrderAttribute.cs
  2. 1
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/PropertyGridUtilities.cs
  3. 12
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/PropertyItem.cs
  4. 1
      ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/WPFToolkit.Extended.csproj

15
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/Attributes/PropertyOrderAttribute.cs

@ -0,0 +1,15 @@
using System;
namespace Microsoft.Windows.Controls.PropertyGrid.Attributes
{
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = true)]
public class PropertyOrderAttribute : Attribute
{
public int Order { get; set; }
public PropertyOrderAttribute(int order)
{
Order = order;
}
}
}

1
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/PropertyGridUtilities.cs

@ -33,6 +33,7 @@ namespace Microsoft.Windows.Controls.PropertyGrid
PropertyItemCollection propertyCollection = new PropertyItemCollection(propertyItems);
propertyCollection.GroupBy("Category");
propertyCollection.SortBy("Category", ListSortDirection.Ascending);
propertyCollection.SortBy("PropertyOrder", ListSortDirection.Ascending);
propertyCollection.SortBy("DisplayName", ListSortDirection.Ascending);
return propertyCollection;
}

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

@ -254,6 +254,8 @@ namespace Microsoft.Windows.Controls.PropertyGrid
public PropertyGrid PropertyGrid { get; private set; }
public int PropertyOrder { get; set; } //maybe make a DP
#region PropertyType
public Type PropertyType
@ -325,6 +327,7 @@ namespace Microsoft.Windows.Controls.PropertyGrid
SetPropertyDescriptorProperties();
ResolveExpandableObject();
ResolvePropertyOrder();
CommandBindings.Add(new CommandBinding(PropertyItemCommands.ResetValue, ExecuteResetValueCommand, CanExecuteResetValueCommand));
AddHandler(Mouse.PreviewMouseDownEvent, new MouseButtonEventHandler(PropertyItem_PreviewMouseDown), true);
@ -402,6 +405,15 @@ namespace Microsoft.Windows.Controls.PropertyGrid
}
}
private void ResolvePropertyOrder()
{
var attrs = PropertyDescriptor.Attributes.OfType<PropertyOrderAttribute>();
if (attrs.Any())
PropertyOrder = attrs.First().Order;
else
PropertyOrder = 0;
}
private void SetPropertyDescriptorProperties()
{
Name = PropertyDescriptor.Name;

1
ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/WPFToolkit.Extended.csproj

@ -274,6 +274,7 @@
<Compile Include="PropertyGrid\Implementation\Attributes\ExpandableObjectAttribute.cs" />
<Compile Include="PropertyGrid\Implementation\Attributes\IItemsSource.cs" />
<Compile Include="PropertyGrid\Implementation\Attributes\ItemsSourceAttribute.cs" />
<Compile Include="PropertyGrid\Implementation\Attributes\PropertyOrderAttribute.cs" />
<Compile Include="PropertyGrid\Implementation\Commands\PropertyGridCommands.cs" />
<Compile Include="PropertyGrid\Implementation\Converters\ValueSourceToImagePathConverter.cs" />
<Compile Include="PropertyGrid\Implementation\Converters\ValueSourceToToolTipConverter.cs" />

Loading…
Cancel
Save