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>
参数
- selection
类型:Microsoft.Windows.Design.Interaction.Selection
当前选定内容
返回值
类型: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 安全性
- 对直接调用方的完全信任。此成员不能由部分信任的代码使用。有关更多信息,请参见通过部分受信任的代码使用库。
请参见
参考
Microsoft.Windows.Design.Policies 命名空间