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 方法,以建立自訂代理原則 (Surrogate Policy)。 如需完整的程式碼清單,請參閱 HOW TO:建立 Surrogate 原則。
' 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 命名空間