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 类在 FeatureProvider 上发现 FeatureConnectorAttribute 时,便会创建指定的 FeatureConnector<TFeatureProviderType>(如果它尚不存在)。

FeatureConnector<TFeatureProviderType> 抽象类实现 IDisposable 接口,后者提升简单的清理实现。

FeatureConnector<TFeatureProviderType> 类的大多数功能在受保护的 CreateFeatureProviders 方法中实现。将一个对象传入此方法会使功能连接器在该对象上搜索 FeatureAttribute 类型。如果找到这些属性,则创建与每个属性相关联的 FeatureProvider 实例并在列表中返回这些实例。

示例

下面的代码示例演示如何从 FeatureConnector<TFeatureProviderType> 类派生以将名为 DiagnosticsMenuProvider 的自定义功能提供程序与名为 IDiagnosticsService 的自定义服务连接起来。有关完整的代码列表,请参见如何:创建自定义功能连接器

' 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 设计器扩展性