FeatureProvider Class

Adds a class-specific contribution to a feature.

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

Syntax

'Declaration
Public MustInherit Class FeatureProvider
'Usage
Dim instance As FeatureProvider
public abstract class FeatureProvider
public ref class FeatureProvider abstract
public abstract class FeatureProvider

Remarks

Derive from the abstract FeatureProvider class to extend the design-time for your custom controls.

Feature providers are managed by feature connectors and are associated to objects through the FeatureAttribute metadata attribute. The feature connector discovers FeatureProvider types from this metadata. The FeatureManager identifies the required feature connector for every feature provider discovered.

Common feature provider implementations include selection adorners, context menus, and property editors.

To attach a feature provider to the primary selection on the design surface, derive from one of the feature providers with the PrimarySelectionPolicy applied, for example PrimarySelectionAdornerProvider or

PrimarySelectionContextMenuProvider.

Examples

The following code example shows how to derive from the FeatureProvider class to implement 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 DiagnosticsMenuProvider class adds a context menu item 
' that displays a dialog box listing the currently running and  
' pending feature connectors. 
<FeatureConnector(GetType(DiagnosticsFeatureConnector))>  _
Public Class DiagnosticsMenuProvider
    Inherits PrimarySelectionContextMenuProvider

    Public Sub New() 
        Dim action As New MenuAction("Feature Diagnostics...")

        AddHandler action.Execute, AddressOf action_Execute 

        Items.Add(action)    
    End Sub 

    Sub action_Execute(ByVal sender As Object, ByVal e As MenuActionEventArgs) 
        Dim service As IDiagnosticsService = e.Context.Services.GetRequiredService(Of IDiagnosticsService)()

        service.ShowWindow()

    End Sub 

End Class
// The DiagnosticsMenuProvider class adds a context menu item 
// that displays a dialog box listing the currently running and  
// pending feature connectors. 
[FeatureConnector(typeof(DiagnosticsFeatureConnector))]
public class DiagnosticsMenuProvider : PrimarySelectionContextMenuProvider 
{
    public DiagnosticsMenuProvider() 
    {
        MenuAction action = new MenuAction("Feature Diagnostics...");

        action.Execute += new EventHandler<MenuActionEventArgs>(action_Execute); 

        Items.Add(action);
    }

    void action_Execute(object sender, MenuActionEventArgs e)
    {
        IDiagnosticsService service = 
            e.Context.Services.GetRequiredService<IDiagnosticsService>();

        service.ShowWindow();
    }
}

Inheritance Hierarchy

System.Object
  Microsoft.Windows.Design.Features.FeatureProvider
    Microsoft.Windows.Design.Interaction.Adapter
    Microsoft.Windows.Design.Interaction.AdornerProvider
    Microsoft.Windows.Design.Interaction.ContextMenuProvider
    Microsoft.Windows.Design.Interaction.TaskProvider
    Microsoft.Windows.Design.Model.DefaultInitializer
    Microsoft.Windows.Design.Model.DesignModeValueProvider
    Microsoft.Windows.Design.Model.InstanceFactory

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

FeatureProvider Members

Microsoft.Windows.Design.Features Namespace

FeatureConnector<TFeatureProviderType>

FeatureManager

PrimarySelectionAdornerProvider

PrimarySelectionContextMenuProvider

Other Resources

How to: Create a Custom Feature Connector

Feature Providers and Feature Connectors

Understanding WPF Designer Extensibility