次の方法で共有


ItemPolicy.GetSurrogateItems メソッド

このアイテムに対するオプションのサロゲート アイテムのセットを返します。

名前空間:  Microsoft.Windows.Design.Policies
アセンブリ:  Microsoft.Windows.Design.Interaction (Microsoft.Windows.Design.Interaction.dll 内)

構文

'宣言
Public Overridable Function GetSurrogateItems ( _
    item As ModelItem _
) As IEnumerable(Of ModelItem)
public virtual IEnumerable<ModelItem> GetSurrogateItems(
    ModelItem item
)
public:
virtual IEnumerable<ModelItem^>^ GetSurrogateItems(
    ModelItem^ item
)
abstract GetSurrogateItems : 
        item:ModelItem -> IEnumerable<ModelItem> 
override GetSurrogateItems : 
        item:ModelItem -> IEnumerable<ModelItem> 
public function GetSurrogateItems(
    item : ModelItem
) : IEnumerable<ModelItem>

パラメーター

戻り値

型: System.Collections.Generic.IEnumerable<ModelItem>
チェックするサロゲート アイテムの列挙体。既定では、空の列挙体が返されます。

解説

サロゲート アイテムは、指定されたアイテムに対する追加機能を提供します。 サロゲート アイテムは、ポリシーのコンシューマーに公開されるアイテムには含まれません。 親オブジェクトから子に機能を提供する場合は、サロゲート アイテムを返す必要があります。 サロゲート アイテムのセットを返すには、true を返すように IsSurrogate プロパティをオーバーライドします。

注意

独自の GetSurrogateItems の実装からは、nullnull 参照 (Visual Basic では Nothing) を返さないようにしてください。

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 デザイナーの機能拡張について