FeatureProvider 类

更新:2007 年 11 月

向功能添加特定于类的基值。

命名空间:  Microsoft.Windows.Design.Features
程序集:  Microsoft.Windows.Design.Extensibility(在 Microsoft.Windows.Design.Extensibility.dll 中)

语法

声明
Public MustInherit Class FeatureProvider
用法
Dim instance As FeatureProvider
public abstract class FeatureProvider
public ref class FeatureProvider abstract
public abstract class FeatureProvider

备注

从 FeatureProvider 抽象类派生以扩展自定义控件的设计时。

功能提供程序由功能连接器管理,并通过 FeatureAttribute 元数据属性与对象相关联。功能连接器从此元数据中发现 FeatureProvider 类型。FeatureManager 标识发现的每个功能提供程序所必需的功能连接器。

常用的功能提供程序实现包括选择装饰器、上下文菜单和属性编辑器。

若要将功能提供程序附加至设计图面上的主选项内容,请从其中一个已应用了 PrimarySelectionPolicy 的功能提供程序派生,例如 PrimarySelectionAdornerProvider

PrimarySelectionContextMenuProvider

示例

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

' 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();
    }
}

继承层次结构

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

线程安全

此类型的任何公共 static(在 Visual Basic 中为 Shared) 成员都是线程安全的。但不保证所有实例成员都是线程安全的。

另请参见

参考

FeatureProvider 成员

Microsoft.Windows.Design.Features 命名空间

FeatureConnector<TFeatureProviderType>

FeatureManager

PrimarySelectionAdornerProvider

PrimarySelectionContextMenuProvider

其他资源

如何:创建自定义功能连接器

功能提供程序和功能连接器

了解 WPF 设计器扩展性