Dela via


PropertyOrder Class

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

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

Syntax

'Declaration
Public NotInheritable Class PropertyOrder _
    Inherits OrderToken
'Usage
Dim instance As PropertyOrder
public sealed class PropertyOrder : OrderToken
public ref class PropertyOrder sealed : public OrderToken
public final class PropertyOrder extends OrderToken

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 


Friend Class Metadata
    Implements IRegisterMetadata

    ' Called by the designer to register any design-time metadata. 
    Public Sub Register() Implements IRegisterMetadata.Register
        Dim builder As New AttributeTableBuilder()

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

        builder.AddCustomAttributes( _
            GetType(Button), _
            FrameworkElement.WidthProperty, _
            New PropertyOrderAttribute( _
                PropertyOrder.CreateBefore( _
                    PropertyOrderTokens.LayoutSizePriority)))

        builder.AddCustomAttributes( _
            GetType(Button), _
            FrameworkElement.VerticalAlignmentProperty, _
            New PropertyOrderAttribute( _
                PropertyOrder.CreateAfter( _
                    PropertyOrderTokens.LayoutAlignmentPriority)))

        builder.AddCustomAttributes( _
            GetType(Button), _
            FrameworkElement.HorizontalAlignmentProperty, _
            New PropertyOrderAttribute( _
                PropertyOrder.CreateBefore( _
                    PropertyOrderTokens.LayoutAlignmentPriority)))

        MetadataStore.AddAttributeTable(builder.CreateTable())

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

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

Inheritance Hierarchy

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

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

PropertyOrder Members

Microsoft.Windows.Design.PropertyEditing Namespace

Other Resources

Property Editing Architecture

WPF Designer Extensibility