是否可以在驻留在 UWP 类库中的 UWP 应用项目中引用和使用 UserControl?我尝试在类库中创建 UserControl,但是当我尝试在应用程序中使用它时,我得到:
App1.exe 中发生“Windows.UI.Xaml.Markup.XamlParseException”类型的异常,但未在用户代码中处理
WinRT 信息:无法从“ms-appx:///ClassLibrary1/MyUserControl1.xaml”找到资源。[线路:10 位置:6]
编辑:我尝试使用 MyUserControl1 的示例页面:
<Page x:Class="App.MainPage"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  xmlns:lib="using:ClassLibrary1"
  xmlns:local="using:App"
  xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  mc:Ignorable="d">
    <Grid>
        <lib:MyUserControl1 />
    </Grid>
</Page>
这是ClassLibrary1中的UserControl
<UserControl x:Class="ClassLibrary1.MyUserControl1"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
         xmlns:local="using:ClassLibrary1"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
         mc:Ignorable="d">
    <Grid />
</UserControl>
编辑2:我没想到这会产生如此大的差异,但是...对库的标准引用工作没有错误,通过 NuGet Package 引用将导致异常发生。对于只有普通类的库,从来没有遇到过这种问题……但是,好吧,既然这是我想要实现的目标,我将重新阐述这个问题。我添加了解决方案架构的屏幕截图: