更新:2007 年 11 月
用於設定屬性出現在分類中的順序,或是出現在子屬性清單中的順序。
命名空間: Microsoft.Windows.Design.PropertyEditing
組件: Microsoft.Windows.Design (在 Microsoft.Windows.Design.dll 中)
語法
Public NotInheritable Class PropertyOrder _
Inherits OrderToken
Dim instance As PropertyOrder
public sealed class PropertyOrder : OrderToken
public ref class PropertyOrder sealed : public OrderToken
public final class PropertyOrder extends OrderToken
備註
建立私用 PropertyOrder 執行個體,以在 [屬性] 視窗中將特定一組屬性組成群組。
PropertyOrder 類別會控制屬性排序,其中包含根屬性與子屬性。根屬性會先整理為不同分類,然後依字母順序排序,最後依 PropertyOrder 排序。子屬性會依 PropertyOrder 排序,然後依字母順序排序。
注意事項: |
|---|
這種行為不同於 Windows Form 設計工具,該設計工具會使用 GetProperties 方法來決定屬性的順序。若為 WPF 設計工具,會使用 PropertyOrder 類別來排序屬性。 |
PropertyOrder 類別會提供標準順序語彙基元 (Token)。這些系統定義的順序語彙基元包含 Early、Default 和 Late 屬性。Early 順序語彙基元會參考 [屬性] 視窗中更高的位置。
會提供 Default 順序給沒有特定屬性順序的屬性。您可以從這個類別衍生,並且建立自己的自訂順序語彙基元,這可保證屬性順序和屬性群組。
範例
下列程式碼範例顯示如何從 PropertyOrder 衍生,以實作
用於 Width 和 Height 屬性的 LayoutSizePriority 類別。這個類別會建立在 Early 順序之後。因此,在清單中它會出現在 Early 屬性的後面。LayoutAlignmentPriority 用於 HorizontalAlignment 和 VerticalAlignment 屬性,而且建立在 LayoutSizePriority 之後。
透過使用 PropertyOrderAttribute,PropertyOrder 執行個體會繫結至屬性。CreateBefore 和 CreateAfter 方法會將 Width 放在 Height 之前並將 HorizontalAlignment 放在 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());
}
}
繼承階層架構
System.Object
Microsoft.Windows.Design.OrderToken
Microsoft.Windows.Design.PropertyEditing.PropertyOrder
執行緒安全
這個型別的任何 Public static (在 Visual Basic 中為 Shared) 成員都具備執行緒安全。並非所有的執行個體成員都是安全執行緒。
請參閱
參考
Microsoft.Windows.Design.PropertyEditing 命名空間
注意事項: