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 设计器扩展性