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 的自訂服務。如需完整的程式碼清單,請參閱 HOW TO:建立自訂功能連接器。
' 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
執行緒安全
這個型別的任何 Public static (在 Visual Basic 中為 Shared) 成員都具備執行緒安全。並非所有的執行個體成員都是安全執行緒。
請參閱
參考
Microsoft.Windows.Design.Features 命名空間
FeatureConnector<TFeatureProviderType>
PrimarySelectionAdornerProvider
PrimarySelectionContextMenuProvider