[UWP] [C ++]无法定义Custom UserControl [英] [UWP][C++]Unable to define Custom UserControl

查看:83
本文介绍了[UWP] [C ++]无法定义Custom UserControl的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我的项目设置如下:



  • CustomControls - Windows运行时组件。这有一个Custom ButtonControl,它基于Button。控件的名称是CustomButton。使用命名空间引用将CustomButton.xaml类中的TargetType设置为CustomButton。
  • CustomLibrary - 使用WINRT API的静态库组件。这包括CustomControls作为参考,并在其CustomLibrary.cpp类中使用CustomButton。
  • TestApp - 包含CustomLibrary作为参考的Windows运行时应用程序,并在其MainPage.xaml中使用CustomLibrary.cpp类.cpp class。



如果我尝试启动TestApp它只是崩溃:

WinRT信息:无法反序列化XBF元数据类型列表,因为在命名空间"CustomControls"中找不到"CustomButton"。 [行:0位置:0]


如果我删除CustomButton类中引用的命名空间并将TargetType设置为Button,则可以正常工作。



基于上面的scneario ,我假设UWP正在尝试对命名空间进行运行时解引用。如果我直接在TestApp中包含CustomControls,那么命名空间问题就不存在了。但是如果中间有一个额外的组件,
这是失败的。

我已经在这里上传了设置:  https://1drv.ms/u/s!AhgimvNrj16ugfNggKWNwTFdbta0tQ

我需要这种结构。那么我在这里错过了什么以及我可以做些什么来解决这个问题?

解决方案

嗨  mayankkrjain,


欢迎
到开发通用Windows应用程序论坛!
  请利用   标记 
发布到此论坛时,谢谢!


在我的测试中,如果您不使用库并直接在TestApp上使用  CustomButton,它会有相同的例外情况。根据我的理解,您设置了  < Style TargetType =" local:CustomButton">
在  CustomButton.xaml中,但在TestApp项目中使用它,它找不到  local:CustomButton in theTestApp项目。


但您可以给customButton一个键,并通过项目中的按钮调用静态资源样式。


祝你好运,


微风


Hi,
I have a project set up as follows :

  • CustomControls - A Windows Runtime Component. This has a Custom UserControl which is based out of Button. The name of the control is CustomButton. The TargetType in the CustomButton.xaml class is set to CustomButton using namespace referencing.
  • CustomLibrary - A Static Library component which consumes WINRT APIs. This includes CustomControls as reference and makes use of the CustomButton in it's CustomLibrary.cpp class.
  • TestApp - A Windows Runtime App which includes CustomLibrary as reference and makes use of the CustomLibrary.cpp class in it's MainPage.xaml.cpp class.

If I try to launch the TestApp it simply crashes :
WinRT information: Cannot deserialize XBF metadata type list as 'CustomButton' was not found in namespace 'CustomControls'. [Line: 0 Position: 0]

If I remove the namespace referencing in the CustomButton class and set the TargetType to Button , this works.

Based on the above scneario  , I am assuming that UWP is trying to do a runtime de-referencing of the namespace. If I directly include CustomControls in the TestApp , the namespace issue is not there. But in case of  an extra component in between, this is failing.
I have uploaded the setup here :  https://1drv.ms/u/s!AhgimvNrj16ugfNggKWNwTFdbta0tQ
I need this structure. So what am I missing here and what I can do to resolve this ?

解决方案

Hi mayankkrjain,

Welcome to the Developing Universal Windows apps forum! Please utilize tagging when posting to this forum, thanks!

In my test, if you don't use the Library and use the CustomButton directly on the TestApp, it has the same exception. According to my understanding, you set the <Style TargetType="local:CustomButton"> in the CustomButton.xaml, but using it on the TestApp project, it can not find the local:CustomButton in theTestApp project.

But you can give a key to the customButton, and call static resource style by a button in the project.

Best regards,

Breeze


这篇关于[UWP] [C ++]无法定义Custom UserControl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆