使用类库 dll 中的 UserControl 时出现 XamlParseException [英] XamlParseException when using UserControl from class library dll

查看:21
本文介绍了使用类库 dll 中的 UserControl 时出现 XamlParseException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个库,它有一个弹出用户控件 与这里的相似.

I have created a library which has a Popup UserControl similar to the one here.

当我创建一个新的通用 Windows 应用程序并在应用程序中创建相同的 UserControl 并打开弹出窗口时,它会打开.

When I create a fresh Universal Windows App and create the same UserControl inside an app and open the popup, it opens.

但是如果我创建一个类库并在其中创建相同的 UserControl 并尝试在应用程序中使用它(通过打开弹出窗口),我会收到 XamlParseException.

But if I create a Class Library and create the same UserControl inside it and try to use it (by opening the popup) inside an app, I get a XamlParseException.

如下——

发生 Windows.UI.Xaml.Markup.XamlParseException
HResult=-2144665590
Message=XAML 解析失败.
来源=Windows
堆栈跟踪:
在 Windows.UI.Xaml.Application.LoadComponent(Object component, Uri resourceLocator, ComponentResourceLocation组件资源位置)
在 PopupTestLibrary.MyUserControl1.InitializeComponent()

Windows.UI.Xaml.Markup.XamlParseException occurred
HResult=-2144665590
Message=XAML parsing failed.
Source=Windows
StackTrace:
at Windows.UI.Xaml.Application.LoadComponent(Object component, Uri resourceLocator, ComponentResourceLocation componentResourceLocation)
at PopupTestLibrary.MyUserControl1.InitializeComponent()

我无法确切理解为什么会发生这种情况,因为代码在不从外部类库中调用时可以正常工作.

I am not able to understand exactly why this is happening, since the code works fine when not called from an external class library.

我发现的一些问题与我的类似,在此 -

Some Questions I found to be similar to mine, here on SO -

从库中使用页面时的 XamlParseException

无法从另一个实例化 UserControl组装

感谢所有帮助!

推荐答案

您需要在您的应用中添加一个资源字典并向其添加 Usercontrol Xaml 内容

You need to Add a Resource Dictionary in your App and Add the Usercontrol Xaml content to it

因为 Xaml 被视为未编译到代码中的内容文件

as Xaml is Considered as a Content file not compiled into the code

这篇关于使用类库 dll 中的 UserControl 时出现 XamlParseException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆