标签:c windows-store-apps windows-8 windows-10 win-universal-app
我已经为Windows Universal Platform(Win 10 UWP)创建了一个类库.
该库包含一些UserControls.
当我将这个库中的dll添加到Win 10 UWP应用程序并使用UserControls时,它会产生一个XamlParseException,如here in another question I posted所述
但是当我引用整个项目时,没有例外,我可以使用UserControl.这可能是因为当我引用dll文件时,有些xbf文件未添加到Win 10应用程序项目中.
在某个项目中,我需要手动将xbf文件添加到Win 10应用程序项目中,我无法引用整个项目,我只能引用dll并添加所需的文件.
我尝试在Visual Studio项目中创建一个文件夹并添加xbf文件,并尝试创建具有不同名称的文件夹,并通过Windows资源管理器将xbf文件复制到“bin”目录中.但没有成功.
那么,我如何手动将xbf文件添加到Windows 10 UWP项目中?
更新1: – XAML&代码供参考
public sealed partial class CustomPopupControl : UserControl
{
internal CustomPopupControl()
{
this.InitializeComponent(); //-------CRASHES HERE-------
}
internal CustomPopupControl() : base()
{
Debug.WriteLine("CustomPopupControl");
//
//do some stuff
//
//
}
private void OnPopupLoaded(object sender, RoutedEventArgs e)
{
this.Popup_Container.HorizontalOffset = (Window.Current.Bounds.Width - Grid_Child.ActualWidth) / 2;
this.Popup_Container.VerticalOffset = (Window.Current.Bounds.Height - Grid_Child.ActualHeight) / 2;
}
internal void OpenPopup()
{
Debug.WriteLine("OpenPopup");
Popup_Container.IsOpen = true;
var currentFrame = Window.Current.Content as Frame;
var currentPage = currentFrame.Content as Page;
currentPage.IsHitTestVisible = false;
Debug.WriteLine("OpenPopup Done");
}
private void OnLayoutUpdated(object sender, object e)
{
if (Grid_Child.ActualWidth == 0 && Grid_Child.ActualHeight == 0)
{
return;
}
double ActualHorizontalOffset = Popup_Container.HorizontalOffset;
double ActualVerticalOffset = Popup_Container.VerticalOffset;
double NewHorizontalOffset = (Window.Current.Bounds.Width - Grid_Child.ActualWidth) / 2;
double NewVerticalOffset = (Window.Current.Bounds.Height - Grid_Child.ActualHeight) / 2;
if (ActualHorizontalOffset != NewHorizontalOffset || ActualVerticalOffset != NewVerticalOffset)
{
Popup_Container.HorizontalOffset = NewHorizontalOffset;
Popup_Container.VerticalOffset = NewVerticalOffset;
}
}
}
XAML: –
<UserControl
x:Class="MyLibrary.CustomPopupControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:MyLibrary"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="300"
d:DesignWidth="400">
<Popup Name="Popup_Container" LayoutUpdated="OnLayoutUpdated">
<Border BorderThickness="1" BorderBrush="{ThemeResource AppBarBorderThemeBrush}">
<Grid Name="Grid_Child">
<Grid Name="Grid_Content" Height="300" Width="400" />
</Grid>
</Border>
</Popup>
我在另一个应用程序中直接使用控件,如 –
CustomPopupControl myctrl = new CustomPopupControl();
myctrl.OpenPopup();
解决方法:
除了Thomas的答案,您还需要在项目的Properties页面下的Build配置中选中“Generate library layout”选项.
我们需要引用的文件:
> ClassLibrary1(类库名称)文件夹
> ClassLibrary1.xr.xml
> CustomPopupControl.xaml
> ClassLibrary1.dll
> ClassLibrary1.pri – >包资源索引文件
将这些文件复制到任何地方,UWP项目只需要在Visual Studio中添加对ClassLibrary1.dll文件的引用,所有这些文件都将自动添加.
It just throws a xaml parse exception when I try to use the UserControl on the “InitializeComponent()” method
添加引用时可能缺少.pri文件.
标签:c,windows-store-apps,windows-8,windows-10,win-universal-app 来源: https://codeday.me/bug/20190628/1313743.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。