Поделиться через


FeatureConnector<TFeatureProviderType> Class

Provides a base implementation for all feature connector-based extensibility.

Inheritance Hierarchy

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

Namespace:  Microsoft.Windows.Design.Features
Assembly:  Microsoft.Windows.Design.Extensibility (in Microsoft.Windows.Design.Extensibility.dll)

Syntax

'Declaration
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 does not support generic types or methods.

Type Parameters

  • TFeatureProviderType
    The type of feature provider.

The FeatureConnector<TFeatureProviderType> type exposes the following members.

Constructors

  Name Description
Protected method FeatureConnector<TFeatureProviderType> Initializes a new instance of the FeatureConnector<TFeatureProviderType> class.

Top

Properties

  Name Description
Protected property Context Gets the editing context for the feature connector.
Protected property Manager Gets the FeatureManager for the feature connector.

Top

Methods

  Name Description
Protected method CreateFeatureProviders(Type) Creates a new list of feature providers associated with the feature connector, based on the provided type.
Protected method CreateFeatureProviders<TSubtype>(Type) Creates a new list of feature providers associated with the feature connector, based on the provided type and subtype.
Public method Dispose() Releases all resources used by the FeatureConnector<TFeatureProviderType>.
Protected method Dispose(Boolean) Releases the unmanaged resources used by the FeatureConnector<TFeatureProviderType> and optionally releases the managed resources.
Public method Equals Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected method Finalize Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Overrides Object.Finalize().)
Public method GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Protected method MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public method ToString Returns a string that represents the current object. (Inherited from Object.)

Top

Remarks

Derive from the abstract FeatureConnector<TFeatureProviderType> class when you need to implement the deepest level of integration with the WPF Designer. Feature connectors can subscribe to global services and can add their own services.

Feature providers use FeatureConnectorAttribute to specify the associated feature connector.

The FeatureConnector<TFeatureProviderType> base class is generic and consumes the type of the feature provider that the FeatureConnector<TFeatureProviderType> hosts.

Feature connectors are demand-created. When the FeatureManager class discovers a FeatureConnectorAttribute on a FeatureProvider, it creates the specified FeatureConnector<TFeatureProviderType>, if it does not already exist.

The abstract FeatureConnector<TFeatureProviderType> class implements the IDisposable interface, which promotes a simple cleanup implementation.

Most of the functionality of the FeatureConnector<TFeatureProviderType> class is implemented in the protected CreateFeatureProviders methods. Passing an object into this method causes the feature connector to search for FeatureAttribute types on the object. If these attributes are found, the FeatureProvider instance associated with each attribute is created and returned in a list.

Examples

The following code example shows how to derive from the FeatureConnector<TFeatureProviderType> class to connect a custom feature provider named DiagnosticsMenuProvider with a custom service named IDiagnosticsService. For a complete code listing, see How to: Create a Custom Feature Connector.

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

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See Also

Reference

Microsoft.Windows.Design.Features Namespace

FeatureManager

FeatureProvider

FeatureConnectorAttribute

Other Resources

How to: Create a Custom Feature Connector

Feature Providers and Feature Connectors

Understanding WPF Designer Extensibility