次の方法で共有


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 の場合は、使用可能にするアクティブなタスクのセットと、デザイン サーフェイス上に表示する装飾のセットを取得します。

デザイナがメタデータからポリシーの種類を検出するたびに、そのポリシーのインスタンスが 1 つアクティブになります。ポリシーはデザイナの有効期間中存続し、デザイナが破棄されるまで非アクティブになることはありません。プロセス グローバルなリソースへの参照を保持するポリシーがある場合は、ポリシー マネージャの終了時に呼び出される 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 デザイナの機能拡張について