ItemPolicy.IsSurrogate 属性

获取一个值,该值指示策略是否为代理项策略。

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

语法

声明
Public Overridable ReadOnly Property IsSurrogate As Boolean
    Get
public virtual bool IsSurrogate { get; }
public:
virtual property bool IsSurrogate {
    bool get ();
}
abstract IsSurrogate : bool
override IsSurrogate : bool
function get IsSurrogate () : boolean

属性值

类型:System.Boolean
如果策略是代理项策略,则为 true,否则为 false。

备注

代理项政策提供了用于查找功能提供程序的备用项目集。 代理项策略通常由控件容器使用,该容器可以在它们的子级上提供其他任务和装饰器。 在此方案中,容器提供代理项策略,GetSurrogateItems 方法在其中返回所提供项的父级。

示例

下面的代码示例演示如何通过实现 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 安全性

请参见

参考

ItemPolicy 类

Microsoft.Windows.Design.Policies 命名空间

PrimarySelectionPolicy

SelectionPolicy

FeatureProvider

FeatureConnectorAttribute

其他资源

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

了解 WPF 设计器扩展性