ItemPolicy 类

更新:2007 年 11 月

一个在设计器中指定一组规则的策略。

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

语法

声明
Public MustInherit Class ItemPolicy
用法
Dim instance As ItemPolicy
public abstract class ItemPolicy
public ref class ItemPolicy abstract
public abstract class ItemPolicy

备注

可从 ItemPolicy 抽象类派生,以便在一组项与对应的功能提供程序之间提供关联。

使用策略可以发现正在设计器中运行的项上的扩展性功能。策略由工具、装饰器及设计器中其他可扩展的区域使用。SelectionPolicy 类是策略的一个示例,它监视选定内容更改并在选定内容更改时引发 PolicyItemsChanged 事件。设计器处理所有正在运行的策略的更改事件并采取适当的措施。如果是 SelectionPolicy,设计器会查询一组应该可用的活动任务和一组应该在设计图面上显示的装饰器。

当设计器在元数据中发现某个策略类型时便会激活该策略类型的一个实例。策略在设计器的整个生存期都存在,并且如果不对设计器本身进行处理,策略就永远不会停用。如果您有一个保存对进程全局资源的引用的策略,请实现 OnDeactivated 方法,当策略管理器终止时会调用该方法。

示例

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

' 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

线程安全

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

另请参见

参考

ItemPolicy 成员

Microsoft.Windows.Design.Policies 命名空间

PrimarySelectionPolicy

SelectionPolicy

FeatureProvider

FeatureConnectorAttribute

其他资源

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

了解 WPF 设计器扩展性