xaml - UWP 中缺少类库文件的 xaml.xr

标签 xaml uwp class-library

我有一个在 UWP 项目中使用的类库项目。如果我在类库中添加任何 usercontrol xaml 文件并构建它,它构建得很好。但是 UWP 项目给出了找不到 .xr 文件的错误。

我是否需要将任何文件夹中的 .xr 文件从外部添加到我的 UWP 项目?

最佳答案

是的,对于带有XAML文件的类库,如果我们想引用其他项目中的dll,我们不仅需要dll本身,还需要.xr.xaml文件和其他一些文件。因为在 UWP 环境中,资源不再嵌入到程序集中,而是作为内容放置在 dll 旁边。查看类似案例:How to add xbf files to visual studio project .

The files we need to reference like following:

  • ClassLibrary1(Class Library name) Folder
    • ClassLibrary1.xr.xml
    • UserControl.xaml (UserControl XAML file)
  • ClassLibrary1.dll
  • ClassLibrary1.pri

To get these files, we can check the "Generate library layout" option in the Build configuration under the project's Properties page.



然后我们可以将这些文件复制到任何地方,UWP 项目只需要在 Visual Studio 中添加对 ClassLibrary1.dll 文件的引用,Visual Studio 会在构建应用程序时自动拾取这些文件并将它们放入 appx 包中。

关于xaml - UWP 中缺少类库文件的 xaml.xr,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34847919/

相关文章:

c# - WPF图像源来自常量

c# - WPF 控件初始化时未更新属性

xaml - Windows Phone 8.1 通用应用程序中的字段验证

c# - 窗口标题文本颜色的主题资源是什么?

c# - UWP XAML 编辑器不起作用

c# - 错误 CS0103 : The name does not exist in the current context when debugging referenced project

c# - WPF Expander 在 Canvas 内部时不会向左扩展

c# - DNN 7 Web API 模块;无法加载文件或程序集

c# - 在 Windows 服务器机器上注册用 C# 编写的 Dll -(安装 C# 类库)

c# - 由于 DPI 意识,Microsoft Store 认证失败