gpt4 book ai didi

c# - 如何从外部类库(通过 NuGet 包)引用 UserControl?

转载 作者:行者123 更新时间:2023-11-30 16:04:39 25 4
gpt4 key购买 nike

是否可以在驻留在 UWP 类库中的 UWP 应用项目中引用和使用 UserControl?我尝试在类库中创建一个 UserControl,但是当我尝试在应用程序中使用它时,我得到:

“Windows.UI.Xaml.Markup.XamlParseException”类型的异常发生在 App1.exe 中,但未在用户代码中处理

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 包引用将导致异常发生。对于只有普通类的库,从来没有遇到过这种问题……但是,好吧,既然这是我想要实现的目标,我将重新表述这个问题。我添加了解决方案架构的屏幕截图:

Solution

最佳答案

解决了这个链接:https://dschenkelman.github.io/2014/06/25/windows-phone-8-1-nuget-packages-with-xaml-components/

当您拥有包含 XAML 组件的 NuGet 包时,您必须手动包含 XAML 二进制文件 (.xbf),否则解析将失败。嗯,很高兴知道,但真让人头疼!

关于c# - 如何从外部类库(通过 NuGet 包)引用 UserControl?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34742349/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com