Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

PropertyOrder Class

Used to set the order in which properties appear in a category, or in a list of sub-properties.

System.Object
  Microsoft.Windows.Design.OrderToken
    Microsoft.Windows.Design.PropertyEditing.PropertyOrder

Namespace:  Microsoft.Windows.Design.PropertyEditing
Assembly:  Microsoft.Windows.Design.Interaction (in Microsoft.Windows.Design.Interaction.dll)

public sealed class PropertyOrder : OrderToken

The PropertyOrder type exposes the following members.

  NameDescription
Public propertyStatic memberDefaultGets the system-defined default order position.
Public propertyStatic memberEarlyGets the system-defined early order position.
Public propertyStatic memberLateGets the system-defined late order position.
Top

  NameDescription
Public methodCompareToCompares this order token with the specified order token. (Inherited from OrderToken.)
Public methodStatic memberCreateAfterCreates a PropertyOrder object that is added after the specified token.
Public methodStatic memberCreateBeforeCreates a PropertyOrder object that is added before the specified token.
Public methodEqualsDetermines whether the specified Object is equal to the current Object. (Inherited from OrderToken.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from OrderToken.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Protected methodResolveConflictCalled by the default CompareTo implementation when two OrderToken objects appear to be equivalent. (Inherited from OrderToken.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

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.

NoteNote

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;
        }
    }
}

// Container for any general design-time metadata to initialize.
// Designers look for a type in the design-time assembly that 
// implements IProvideAttributeTable. If found, designers instantiate 
// this class and access its AttributeTable property automatically.
internal class Metadata : IProvideAttributeTable
{
    // Accessed by the designer to register any design-time metadata.
    public AttributeTable AttributeTable
    {
        get
        {
            AttributeTableBuilder builder = new AttributeTableBuilder();

            builder.AddCustomAttributes(
                typeof(Button),
                "Height",
                new PropertyOrderAttribute(
                    PropertyOrder.CreateAfter(
                    PropertyOrderTokens.LayoutSizePriority)));

            builder.AddCustomAttributes(
                typeof(Button),
                "Width",
                new PropertyOrderAttribute(
                    PropertyOrder.CreateBefore(
                    PropertyOrderTokens.LayoutSizePriority)));

            builder.AddCustomAttributes(
                typeof(Button),
                "VerticalAlignment",
                new PropertyOrderAttribute(
                    PropertyOrder.CreateAfter(
                    PropertyOrderTokens.LayoutAlignmentPriority)));

            builder.AddCustomAttributes(
                typeof(Button),
                "HorizontalAlignment",
                new PropertyOrderAttribute(
                    PropertyOrder.CreateBefore(
                    PropertyOrderTokens.LayoutAlignmentPriority)));

            return builder.CreateTable();
        }
    }
}


Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Community Additions

ADD
Show:
© 2015 Microsoft