共用方式為


PrimarySelectionPolicy 類別

更新:2007 年 11 月

會指定主要選取項目的原則。

命名空間:  Microsoft.Windows.Design.Policies
組件:  Microsoft.Windows.Design.Extensibility (在 Microsoft.Windows.Design.Extensibility.dll 中)

語法

Public Class PrimarySelectionPolicy _
    Inherits SelectionPolicy

Dim instance As PrimarySelectionPolicy
public class PrimarySelectionPolicy : SelectionPolicy
public ref class PrimarySelectionPolicy : public SelectionPolicy
public class PrimarySelectionPolicy extends SelectionPolicy

備註

PrimarySelectionPolicy 類別是 ItemPolicy,當 SelectionTool 為使用中的工具時便會啟用,以供主要選取項目使用。

範例

下列程式碼範例示範如何實作主要選取的自訂代理原則。如需完整的程式碼清單,請參閱 HOW TO:建立 Surrogate 原則

' The DockPanelPolicy class implements a surrogate policy that
' provides container semantics for a selected item. By using 
' this policy, the DemoDockPanel container control offers 
' additional tasks and adorners on its children. 
Class DockPanelPolicy
    Inherits PrimarySelectionPolicy

    Public Overrides ReadOnly Property IsSurrogate() As Boolean 
        Get
            Return True
        End Get
    End Property

    Public Overrides Function GetSurrogateItems( _
        ByVal item As Microsoft.Windows.Design.Model.ModelItem) _
        As System.Collections.Generic.IEnumerable( _
        Of Microsoft.Windows.Design.Model.ModelItem)

        Dim parent As ModelItem = item.Parent

        Dim e As New System.Collections.Generic.List(Of ModelItem)

        If (parent IsNot Nothing) Then

            e.Add(parent)

        End If

        Return e

    End Function

End Class
// The DockPanelPolicy class implements a surrogate policy that
// provides container semantics for a selected item. By using 
// this policy, the DemoDockPanel container control offers 
// additional tasks and adorners on its children. 
class DockPanelPolicy : PrimarySelectionPolicy 
{
    public override bool IsSurrogate 
    {
        get 
        { 
            return true;
        }
    }

    public override IEnumerable<ModelItem> GetSurrogateItems(ModelItem item) 
    {
        ModelItem parent = item.Parent;

        if (parent != null)
        {
            yield return parent;
        }
    }
}

繼承階層架構

System.Object
  Microsoft.Windows.Design.Policies.ItemPolicy
    Microsoft.Windows.Design.Policies.SelectionPolicy
      Microsoft.Windows.Design.Policies.PrimarySelectionPolicy

執行緒安全

這個型別的任何 Public static (在 Visual Basic 中為 Shared) 成員都具備執行緒安全。並非所有的執行個體成員都是安全執行緒。

請參閱

參考

PrimarySelectionPolicy 成員

Microsoft.Windows.Design.Policies 命名空間

ItemPolicy

SelectionPolicy

FeatureProvider

FeatureConnectorAttribute

其他資源

功能提供者和功能連接器

了解 WPF 設計工具擴充性