SelectionPolicy 类

[本文档仅供预览,在以后的发行版中可能会发生更改。包含的空白主题用作占位符。]

使所有项目可选的策略。

继承层次结构

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

命名空间:  Microsoft.Windows.Design.Policies
程序集:  Microsoft.Windows.Design.Interaction(在 Microsoft.Windows.Design.Interaction.dll 中)

语法

声明
<RequiresContextItemAttribute(GetType(Selection))> _
<RequiresContextItemAttribute(GetType(Tool))> _
Public Class SelectionPolicy _
    Inherits ItemPolicy
[RequiresContextItemAttribute(typeof(Selection))]
[RequiresContextItemAttribute(typeof(Tool))]
public class SelectionPolicy : ItemPolicy
[RequiresContextItemAttribute(typeof(Selection))]
[RequiresContextItemAttribute(typeof(Tool))]
public ref class SelectionPolicy : public ItemPolicy
[<RequiresContextItemAttribute(typeof(Selection))>]
[<RequiresContextItemAttribute(typeof(Tool))>]
type SelectionPolicy =  
    class
        inherit ItemPolicy
    end
public class SelectionPolicy extends ItemPolicy

SelectionPolicy 类型公开以下成员。

构造函数

  名称 说明
公共方法 SelectionPolicy 初始化 SelectionPolicy 类的新实例。

页首

属性

  名称 说明
受保护的属性 Context 获取设计器的编辑上下文。 (继承自 ItemPolicy。)
公共属性 IsSurrogate 获取一个值,该值指示策略是否为代理项策略。 (继承自 ItemPolicy。)
公共属性 PolicyItems 获取受此策略影响的对象的枚举。 (重写 ItemPolicy.PolicyItems。)

页首

方法

  名称 说明
公共方法 Equals 确定指定的 Object 是否等于当前的 Object。 (继承自 Object。)
受保护的方法 Finalize 允许对象在“垃圾回收”回收之前尝试释放资源并执行其他清理操作。 (继承自 Object。)
公共方法 GetHashCode 用作特定类型的哈希函数。 (继承自 Object。)
受保护的方法 GetPolicyItems 从指定的选择中返回策略项。
公共方法 GetSurrogateItems 返回此项的代理项的可选集合。 (继承自 ItemPolicy。)
公共方法 GetType 获取当前实例的 Type。 (继承自 Object。)
受保护的方法 IsInPolicy 获取指示指定项是否被包含在策略中的值。
受保护的方法 MemberwiseClone 创建当前 Object 的浅表副本。 (继承自 Object。)
受保护的方法 OnActivated 当激活此策略时调用。 (重写 ItemPolicy.OnActivated()。)
受保护的方法 OnDeactivated 当停用此策略时调用。 (重写 ItemPolicy.OnDeactivated()。)
受保护的方法 OnPolicyItemsChanged 引发 PolicyItemsChanged 事件。 (继承自 ItemPolicy。)
公共方法 ToString 返回表示当前对象的字符串。 (继承自 Object。)

页首

事件

  名称 说明
公共事件 PolicyItemsChanged 当策略更改时发生。 (继承自 ItemPolicy。)

页首

备注

通过此策略并且重写IsInPolicyGetPolicyItems 方法以根据需要过滤选择。

示例

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

' 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;
        }
    }
}

线程安全

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

请参见

参考

Microsoft.Windows.Design.Policies 命名空间

ItemPolicy

FeatureProvider

FeatureConnector<TFeatureProviderType>

其他资源

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

了解 WPF 设计器扩展性