Share via


Application.LoadComponent 方法

定义

重载

LoadComponent(Object, Uri)

加载位于指定相对位置的 XAML 文件,并将其转换为由 XAML 文件的根元素指定的 对象的实例。

LoadComponent(Object, Uri, ComponentResourceLocation)

加载位于指定相对位置的 XAML 文件,并将其转换为由 XAML 文件的根元素指定的 对象的实例。

LoadComponent(Object, Uri)

加载位于指定相对位置的 XAML 文件,并将其转换为由 XAML 文件的根元素指定的 对象的实例。

public:
 static void LoadComponent(Platform::Object ^ component, Uri ^ resourceLocator);
/// [Windows.Foundation.Metadata.Overload("LoadComponent")]
 static void LoadComponent(IInspectable const& component, Uri const& resourceLocator);
[Windows.Foundation.Metadata.Overload("LoadComponent")]
public static void LoadComponent(object component, System.Uri resourceLocator);
function loadComponent(component, resourceLocator)
Public Shared Sub LoadComponent (component As Object, resourceLocator As Uri)

参数

component
Object

Platform::Object

IInspectable

与要加载的 XAML 内容的根元素类型相同的对象。

resourceLocator
Uri Uri

描述统一资源标识符 (URI 的对象) 要加载的资源的路径。

属性

注解

LoadComponent 主要针对基础结构存在。 你可以看到 LoadComponent 作为生成的 InitializeComponent 逻辑的一部分,该逻辑集成了 XAML 页面的分部类及其代码隐藏。

LoadComponent 有时在调用堆栈中引用异常,该异常最终是因为应用尝试分析错误的 XAML。 在这种情况下,应用代码无法更改 LoadComponent 的使用方式,修复该问题的方法是在 XML 编辑器中检查 XAML 源并修复它。 堆栈跟踪消息中可能有用的是确认未加载哪个 XAML 文件。 在已合并资源或正在合并其他多个 XAML 源的情况下,无法分析的并非总是明显的页面级 XAML。

涉及加载 XAML 内容和生成对象树的大多数应用方案都应改用 XamlReader.Load

另请参阅

适用于

LoadComponent(Object, Uri, ComponentResourceLocation)

加载位于指定相对位置的 XAML 文件,并将其转换为由 XAML 文件的根元素指定的 对象的实例。

public:
 static void LoadComponent(Platform::Object ^ component, Uri ^ resourceLocator, ComponentResourceLocation componentResourceLocation);
/// [Windows.Foundation.Metadata.Overload("LoadComponentWithResourceLocation")]
 static void LoadComponent(IInspectable const& component, Uri const& resourceLocator, ComponentResourceLocation const& componentResourceLocation);
[Windows.Foundation.Metadata.Overload("LoadComponentWithResourceLocation")]
public static void LoadComponent(object component, System.Uri resourceLocator, ComponentResourceLocation componentResourceLocation);
function loadComponent(component, resourceLocator, componentResourceLocation)
Public Shared Sub LoadComponent (component As Object, resourceLocator As Uri, componentResourceLocation As ComponentResourceLocation)

参数

component
Object

Platform::Object

IInspectable

与要加载的 XAML 内容的根元素类型相同的对象。

resourceLocator
Uri Uri

描述统一资源标识符 (URI 的对象) 要加载的资源的路径。

componentResourceLocation
ComponentResourceLocation

枚举的一个值。

属性

另请参阅

适用于