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 方法来创建自定义代理项策略。 有关完整的代码清单,请参见如何:创建代理项策略

' 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 设计器扩展性