语言

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

枚举的值。

属性

另请参阅

适用于