PropertyOrder Class

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

Inheritance Hierarchy

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)

Syntax

'Declaration
Public NotInheritable Class PropertyOrder _
    Inherits OrderToken
public sealed class PropertyOrder : OrderToken
public ref class PropertyOrder sealed : public OrderToken
[<Sealed>]
type PropertyOrder =  
    class
        inherit OrderToken
    end
public final class PropertyOrder extends OrderToken

The PropertyOrder type exposes the following members.

Properties

  Name Description
Public propertyStatic member Default Gets the system-defined default order position.
Public propertyStatic member Early Gets the system-defined early order position.
Public propertyStatic member Late Gets the system-defined late order position.

Top

Methods

  Name Description
Public method CompareTo Compares this order token with the specified order token. (Inherited from OrderToken.)
Public methodStatic member CreateAfter Creates a PropertyOrder object that is added after the specified token.
Public methodStatic member CreateBefore Creates a PropertyOrder object that is added before the specified token.
Public method Equals Determines whether the specified Object is equal to the current Object. (Inherited from OrderToken.)
Protected method Finalize Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public method GetHashCode Serves as a hash function for a particular type. (Inherited from OrderToken.)
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Protected method MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Protected method ResolveConflict Called by the default CompareTo implementation when two OrderToken objects appear to be equivalent. (Inherited from OrderToken.)
Public method ToString Returns a string that represents the current object. (Inherited from Object.)

Top

Remarks

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.

Examples

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.

Imports System
Imports System.Windows
Imports System.Windows.Controls
Imports Microsoft.Windows.Design.PropertyEditing
Imports Microsoft.Windows.Design.Metadata

Public Class PropertyOrderTokens
    Private Shared layoutSizePriorityValue As PropertyOrder
    Private Shared layoutAlignmentPriorityValue As PropertyOrder


    Public Shared ReadOnly Property LayoutSizePriority() As PropertyOrder
        Get
            If layoutSizePriorityValue Is Nothing Then
                LayoutSizePriority = PropertyOrder.CreateAfter(PropertyOrder.Early)
            End If

            Return layoutSizePriorityValue
        End Get
    End Property


    Public Shared ReadOnly Property LayoutAlignmentPriority() As PropertyOrder
        Get
            If layoutAlignmentPriorityValue Is Nothing Then
                layoutAlignmentPriorityValue = PropertyOrder.CreateAfter(PropertyOrderTokens.LayoutSizePriority)
            End If

            Return layoutAlignmentPriorityValue
        End Get
    End Property
End Class

' 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.
Friend Class Metadata
    Implements IProvideAttributeTable

    ' Accessed by the designer to register any design-time metadata.
    Public ReadOnly Property AttributeTable() As AttributeTable _
        Implements IProvideAttributeTable.AttributeTable
        Get
            Dim builder As New AttributeTableBuilder()

            builder.AddCustomAttributes( _
                GetType(Button), _
                "HeightProperty", _
                New PropertyOrderAttribute( _
                    PropertyOrder.CreateAfter( _
                        PropertyOrderTokens.LayoutSizePriority)))

            builder.AddCustomAttributes( _
                GetType(Button), _
                "Width", _
                New PropertyOrderAttribute( _
                    PropertyOrder.CreateBefore( _
                        PropertyOrderTokens.LayoutSizePriority)))

            builder.AddCustomAttributes( _
                GetType(Button), _
                "VerticalAlignment", _
                New PropertyOrderAttribute( _
                    PropertyOrder.CreateAfter( _
                        PropertyOrderTokens.LayoutAlignmentPriority)))

            builder.AddCustomAttributes( _
                GetType(Button), _
                "HorizontalAlignment", _
                New PropertyOrderAttribute( _
                    PropertyOrder.CreateBefore( _
                        PropertyOrderTokens.LayoutAlignmentPriority)))

            Return builder.CreateTable()
        End Get
    End Property
End Class
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();
        }
    }
}

Thread Safety

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

See Also

Reference

Microsoft.Windows.Design.PropertyEditing Namespace

Other Resources

Property Editing Architecture

WPF Designer Extensibility