次の方法で共有


FeatureConnector<TFeatureProviderType> クラス

更新 : 2007 年 11 月

機能コネクタ ベースの全機能拡張の基本実装を提供します。

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

構文

'宣言
Public MustInherit Class FeatureConnector(Of TFeatureProviderType As FeatureProvider) _
    Implements IDisposable
'使用
Dim instance As FeatureConnector(Of TFeatureProviderType)
public abstract class FeatureConnector<TFeatureProviderType> : IDisposable
where TFeatureProviderType : FeatureProvider
generic<typename TFeatureProviderType>
where TFeatureProviderType : FeatureProvider
public ref class FeatureConnector abstract : IDisposable
JScript では、ジェネリックな型またはメソッドは使用できません。

型パラメータ

  • TFeatureProviderType
    機能プロバイダの型。

解説

最下位レベルでの WPF デザイナとの統合を実装する必要がある場合に、抽象 FeatureConnector<TFeatureProviderType> クラスから派生します。機能コネクタは、グローバル サービスをサブスクライブし、独自のサービスを追加できます。

機能プロバイダは FeatureConnectorAttribute を使用して、関連付けられた機能コネクタを指定します。

FeatureConnector<TFeatureProviderType> 基本クラスはジェネリックであり、FeatureConnector<TFeatureProviderType> がホストする機能プロバイダの型を使用します。

機能コネクタは要求に応じて作成されます。FeatureManager クラスが FeatureProviderFeatureConnectorAttribute を検出したときに、その機能コネクタがまだ存在していない場合、機能マネージャは指定された FeatureConnector<TFeatureProviderType> を作成します。

抽象 FeatureConnector<TFeatureProviderType> クラスは、シンプルな後処理実装を行う IDisposable インターフェイスを実装します。

FeatureConnector<TFeatureProviderType> クラスの機能のほとんどは、プロテクト CreateFeatureProviders メソッドで実装されます。オブジェクトがこのメソッドに渡されると、機能コネクタは、そのオブジェクトの FeatureAttribute 型を探します。これらの属性が見つかると、この属性に関連付けられた FeatureProvider インスタンスが作成され、リストで返されます。

FeatureConnector<TFeatureProviderType> クラスから派生して、IDiagnosticsService という名前のカスタム サービスと DiagnosticsMenuProvider という名前のカスタム機能プロバイダを関連付ける方法を次のコード例に示します。完全なコードの一覧については、「方法 : カスタム機能コネクタを作成する」を参照してください。

' The IDiagnosticsService specifies a simple interface for showing
' a FeatureManagerDiagnostics window.
Interface IDiagnosticsService
    Sub ShowWindow() 
End Interface


...


' The DiagnosticsFeatureConnector publishes the IDiagnosticsService. 
Class DiagnosticsFeatureConnector
    Inherits FeatureConnector(Of DiagnosticsMenuProvider)
    Implements IDiagnosticsService

    Dim fmdWindow As FeatureManagerDiagnostics

    Public Sub New(ByVal manager As FeatureManager) 
        MyBase.New(manager)

        Context.Services.Publish(Of IDiagnosticsService)(Me)

    End Sub

    ' The showWindow method creates a FeatureManagerDiagnostics
    ' window and shows it.
    Public Sub ShowWindow() Implements IDiagnosticsService.ShowWindow

        If fmdWindow IsNot Nothing Then

            ' Show the FeatureManagerDiagnostics window.
            fmdWindow.Show()

            ' Activate the 
            fmdWindow.Activate()

        Else

            fmdWindow = New FeatureManagerDiagnostics()
            fmdWindow.Initialize(Manager)
            AddHandler fmdWindow.Closed, AddressOf fmdWindow_Closed
            fmdWindow.Show()

        End If

    End Sub

    Sub fmdWindow_Closed(ByVal sender As Object, ByVal e As EventArgs)

        fmdWindow = Nothing

    End Sub

End Class
// The IDiagnosticsService specifies a simple interface for showing
// a FeatureManagerDiagnostics window.
interface IDiagnosticsService 
{
    void ShowWindow();
}


...


// The DiagnosticsFeatureConnector publishes the IDiagnosticsService. 
class DiagnosticsFeatureConnector : FeatureConnector<DiagnosticsMenuProvider>,
    IDiagnosticsService 
{
    FeatureManagerDiagnostics fmdWindow;

    public DiagnosticsFeatureConnector(FeatureManager manager)
        : base(manager) 
    {
        Context.Services.Publish<IDiagnosticsService>(this);
    }

    #region IDiagnosticsService Members

    // The showWindow method creates a FeatureManagerDiagnostics
    // window and shows it.
    public void ShowWindow() 
    {
        if (fmdWindow != null) 
        {
            fmdWindow.Show();
            fmdWindow.Activate();
        }
        else 
        {
            fmdWindow = new FeatureManagerDiagnostics();
            fmdWindow.Initialize(Manager);
            fmdWindow.Closed += new EventHandler(fmdWindow_Closed); 
            fmdWindow.Show();
        }
    }

    void fmdWindow_Closed(object sender, EventArgs e)
    {
        fmdWindow = null; 
    }

    #endregion
}

継承階層

System.Object
  Microsoft.Windows.Design.Features.FeatureConnector<TFeatureProviderType>
    Microsoft.Windows.Design.Features.PolicyDrivenFeatureConnector<TFeatureProviderType>

スレッド セーフ

この型のすべてのパブリック static (Visual Basic では Shared) メンバは、スレッド セーフです。インスタンス メンバの場合は、スレッド セーフであるとは限りません。

参照

参照

FeatureConnector<TFeatureProviderType> メンバ

Microsoft.Windows.Design.Features 名前空間

FeatureManager

FeatureProvider

FeatureConnectorAttribute

その他の技術情報

方法 : カスタム機能コネクタを作成する

機能プロバイダと機能コネクタ

WPF デザイナの機能拡張について