共用方式為


FeatureConnector<TFeatureProviderType> 類別

提供以功能連接器為基礎之完整擴充性的基底實作。

繼承階層架構

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

命名空間:  Microsoft.Windows.Design.Features
組件:  Microsoft.Windows.Design.Extensibility (在 Microsoft.Windows.Design.Extensibility.dll 中)

語法

'宣告
Public MustInherit Class FeatureConnector(Of TFeatureProviderType As FeatureProvider) _
    Implements IDisposable
public abstract class FeatureConnector<TFeatureProviderType> : IDisposable
where TFeatureProviderType : FeatureProvider
generic<typename TFeatureProviderType>
where TFeatureProviderType : FeatureProvider
public ref class FeatureConnector abstract : IDisposable
[<AbstractClass>]
type FeatureConnector<'TFeatureProviderType when 'TFeatureProviderType : FeatureProvider> =  
    class
        interface IDisposable
    end
JScript 不支援泛型型別或方法。

型別參數

  • TFeatureProviderType
    功能提供者的型別。

FeatureConnector<TFeatureProviderType> 型別會公開下列成員。

建構函式

  名稱 說明
受保護的方法 FeatureConnector<TFeatureProviderType> 初始化 FeatureConnector<TFeatureProviderType> 類別的新執行個體。

回頁首

屬性

  名稱 說明
受保護的屬性 Context 取得功能連接器的編輯內容。
受保護的屬性 Manager 取得功能連接器的 FeatureManager

回頁首

方法

  名稱 說明
受保護的方法 CreateFeatureProviders(Type) 會根據所提供的型別,建立與功能連接器相關聯之功能提供者的新清單。
受保護的方法 CreateFeatureProviders<TSubtype>(Type) 會根據所提供的型別和子型別,建立與功能連接器相關聯之功能提供者的新清單。
公用方法 Dispose() 釋放 FeatureConnector<TFeatureProviderType> 所使用的所有資源。
受保護的方法 Dispose(Boolean) 釋放 FeatureConnector<TFeatureProviderType> 使用的 Unmanaged 資源,並選擇性釋放 Managed 資源。
公用方法 Equals 判斷指定的 Object 和目前的 Object 是否相等。 (繼承自 Object)。
受保護的方法 Finalize 允許物件在記憶體回收進行回收之前,嘗試釋放資源並執行其他清除作業。 (覆寫 Object.Finalize()。)
公用方法 GetHashCode 做為特定型別的雜湊函式。 (繼承自 Object)。
公用方法 GetType 取得目前執行個體的 Type。 (繼承自 Object)。
受保護的方法 MemberwiseClone 建立目前 Object 的淺層複本 (Shallow Copy)。 (繼承自 Object)。
公用方法 ToString 傳回表示目前物件的字串。 (繼承自 Object)。

回頁首

備註

當您必須實作與 WPF 設計工具最深層的整合時,可以衍生自抽象 FeatureConnector<TFeatureProviderType> 類別。 功能連接器可以訂閱全域服務,也可以加入連接器自己的服務。

功能提供者會使用 FeatureConnectorAttribute,指定相關聯的功能連接器。

FeatureConnector<TFeatureProviderType> 是泛型基底類別 (Base Class),而且會使用 FeatureConnector<TFeatureProviderType> 所裝載之功能提供者的型別。

功能連接器是視需要而建立。 當 FeatureManager 類別在 FeatureProvider 上發現 FeatureConnectorAttribute,就會建立指定的 FeatureConnector<TFeatureProviderType> (如果不存在的話)。

抽象 FeatureConnector<TFeatureProviderType> 類別會實作 IDisposable 介面,如此會提升簡單清除實作。

FeatureConnector<TFeatureProviderType> 類別的大部分功能都會在受保護的 CreateFeatureProviders 方法中實作。 將物件傳入這個方法會導致功能連接器搜尋該物件的 FeatureAttribute 型別。 如果找到了這些屬性,就會在清單中建立並傳回與每個屬性相關聯的 FeatureProvider 執行個體。

範例

在下列程式碼範例中,會說明如何衍生自 FeatureConnector<TFeatureProviderType> 類別,以連接名為 DiagnosticsMenuProvider 的自訂功能提供者與名為 IDiagnosticsService 的自訂服務。 如需完整的程式碼清單,請參閱 HOW TO:建立自訂功能連接器

' 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
}

執行緒安全

這個型別的任何 Public static (在 Visual Basic 中為 Shared) 成員都具備執行緒安全。並非所有的執行個體成員都是安全執行緒。

請參閱

參考

Microsoft.Windows.Design.Features 命名空間

FeatureManager

FeatureProvider

FeatureConnectorAttribute

其他資源

HOW TO:建立自訂功能連接器

功能提供者和功能連接器

了解 WPF 設計工具擴充性