共用方式為


PrimarySelectionPolicy.GetPolicyItems 方法

傳回表示主要選取的原則項目。

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

語法

'宣告
Protected Overrides Function GetPolicyItems ( _
    selection As Selection _
) As IEnumerable(Of ModelItem)
protected override IEnumerable<ModelItem> GetPolicyItems(
    Selection selection
)
protected:
virtual IEnumerable<ModelItem^>^ GetPolicyItems(
    Selection^ selection
) override
abstract GetPolicyItems : 
        selection:Selection -> IEnumerable<ModelItem> 
override GetPolicyItems : 
        selection:Selection -> IEnumerable<ModelItem> 
protected override function GetPolicyItems(
    selection : Selection
) : IEnumerable<ModelItem>

參數

傳回值

型別:System.Collections.Generic.IEnumerable<ModelItem>
若不是主要選取範圍中的單一項目,就是空的列舉。

範例

下列程式碼範例示範,如何透過實作 IsSurrogate 屬性和 GetSurrogateItems 方法,以建立自訂代理原則 (Surrogate Policy)。 如需完整的程式碼清單,請參閱 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;
        }
    }
}

.NET Framework 安全性

請參閱

參考

PrimarySelectionPolicy 類別

Microsoft.Windows.Design.Policies 命名空間

ItemPolicy

SelectionPolicy

FeatureProvider

FeatureConnectorAttribute

其他資源

功能提供者和功能連接器

了解 WPF 設計工具擴充性