![](/img/trans.png)
[英]How can I ensure that a UserControl defined in a class library is included in a NuGet package?
[英]How to reference a UserControl from an external class library (through a NuGet Package)?
是否可以在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包引用將導致異常發生。 從來沒有像只有普通類的圖書館這樣的問題...但是,好吧,因為這是我想要實現的,我將重新闡述問題。 我添加了解決方案架構的屏幕截圖:
解決了這個鏈接: https : //dschenkelman.github.io/2014/06/25/windows-phone-8-1-nuget-packages-with-xaml-components/
當您使用具有XAML組件的NuGet包時,必須手動包含XAML二進制文件(.xbf),否則解析將失敗。 嗯,很高興知道但是很頭疼!
您的代碼完美無缺。 嘗試重新創建項目。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.