共用方式為


ServiceManager.GetRequiredService<TServiceType> 方法

擷取指定型別之服務的執行個體。

命名空間:  Microsoft.Windows.Design
組件:  Microsoft.Windows.Design.Extensibility (在 Microsoft.Windows.Design.Extensibility.dll 中)

語法

'宣告
Public Function GetRequiredService(Of TServiceType) As TServiceType
public TServiceType GetRequiredService<TServiceType>()
public:
generic<typename TServiceType>
TServiceType GetRequiredService()
member GetRequiredService : unit -> 'TServiceType 
JScript 不支援泛型型別或方法。

型別參數

  • TServiceType

傳回值

型別:TServiceType
所要求之服務型別的執行個體。這個方法永遠不會傳回 nullNull 參照 (即 Visual Basic 中的 Nothing)。

例外狀況

例外狀況 條件
NotSupportedException

沒有所要求型別的服務。

備註

如果無法使用所要求型別的服務,則 GetRequiredService<TServiceType> 會擲回 NotSupportedException。 如果可接受 nullNull 參照 (即 Visual Basic 中的 Nothing) 做為傳回值以取代例外狀況,則改用 GetService。 GetRequiredService<TServiceType> 提供更可靠的合約。

.NET Framework 安全性

請參閱

參考

ServiceManager 類別

Microsoft.Windows.Design 命名空間

EditingContext

ContextItem

其他資源

WPF 設計工具擴充性