PropertyOrder Class
Used to set the order in which properties appear in a category, or in a list of sub-properties.
Assembly: Microsoft.Windows.Design (in Microsoft.Windows.Design.dll)
Create private PropertyOrder instances to group together a particular set of properties in the Properties window.
The PropertyOrder class controls property ordering, which includes root properties and sub-properties. Root properties are ordered first into categories, then alphabetically, and finally by PropertyOrder. Sub-properties are ordered by PropertyOrder and then alphabetically.
Note: |
|---|
This behavior differs from the Windows Forms Designer, which uses the GetProperties method to determine the order of the properties. For the WPF Designer, properties are sorted by using the PropertyOrder class. |
Standard order tokens are provided by the PropertyOrder class. These system-defined order tokens include the Early, Default and Late properties. The Early order token refers to a higher position in the Properties window.
Properties without a specific property order are given the Default order. You can derive from this class and create your own custom order tokens, which can guarantee property order and property grouping.
The following code example shows how to derive from PropertyOrder to implement a
LayoutSizePriority class that is used for the Width and Height properties. It is created after the Early order. Therefore, it appears later in the list than Early properties. The LayoutAlignmentPriority is used for the HorizontalAlignment and VerticalAlignment properties and is created after the LayoutSizePriority.
The PropertyOrder instances are bound to properties by using PropertyOrderAttribute. The CreateBefore and CreateAfter methods position Width before Height and HorizontalAlignment before VerticalAlignment.
using System; using System.Windows; using System.Windows.Controls; using Microsoft.Windows.Design.PropertyEditing; using Microsoft.Windows.Design.Metadata; public static class PropertyOrderTokens { private static PropertyOrder layoutSizePriority; private static PropertyOrder layoutAlignmentPriority; public static PropertyOrder LayoutSizePriority { get { if (layoutSizePriority == null) { layoutSizePriority = PropertyOrder.CreateAfter( PropertyOrder.Early); } return layoutSizePriority; } } public static PropertyOrder LayoutAlignmentPriority { get { if (layoutAlignmentPriority == null) { layoutAlignmentPriority = PropertyOrder.CreateAfter( PropertyOrderTokens.LayoutSizePriority); } return layoutAlignmentPriority; } } } internal class Metadata : IRegisterMetadata { // Called by the designer to register any design-time metadata. public void Register() { AttributeTableBuilder builder = new AttributeTableBuilder(); builder.AddCustomAttributes( typeof( Button ), FrameworkElement.HeightProperty, new PropertyOrderAttribute( PropertyOrder.CreateAfter( PropertyOrderTokens.LayoutSizePriority))); builder.AddCustomAttributes( typeof(Button), FrameworkElement.WidthProperty, new PropertyOrderAttribute( PropertyOrder.CreateBefore( PropertyOrderTokens.LayoutSizePriority))); builder.AddCustomAttributes( typeof(Button), FrameworkElement.VerticalAlignmentProperty, new PropertyOrderAttribute( PropertyOrder.CreateAfter( PropertyOrderTokens.LayoutAlignmentPriority))); builder.AddCustomAttributes( typeof(Button), FrameworkElement.HorizontalAlignmentProperty, new PropertyOrderAttribute( PropertyOrder.CreateBefore( PropertyOrderTokens.LayoutAlignmentPriority))); MetadataStore.AddAttributeTable(builder.CreateTable()); } }
Microsoft.Windows.Design.OrderToken
Microsoft.Windows.Design.PropertyEditing.PropertyOrder
Note: