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

备注

SelectionTool 是活动工具时,PrimarySelectionPolicy 类是为主选定元素启用的 ItemPolicy

示例

下面的代码示例演示如何为主选项内容实现自定义代理项策略。有关完整的代码清单,请参见如何:创建代理项策略

' 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

线程安全

此类型的任何公共 static(在 Visual Basic 中为 Shared) 成员都是线程安全的。但不保证所有实例成员都是线程安全的。

另请参见

参考

PrimarySelectionPolicy 成员

Microsoft.Windows.Design.Policies 命名空间

ItemPolicy

SelectionPolicy

FeatureProvider

FeatureConnectorAttribute

其他资源

功能提供程序和功能连接器

了解 WPF 设计器扩展性