XAML在本地名称空间中找不到引用 [英] XAML cannot find reference in local namespace

查看:249
本文介绍了XAML在本地名称空间中找不到引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Win8(均为RC)上使用VS2012在C ++中创建了一个新的Metro Split App.一切都已编译并立即可用.然后,我进行了更改,并将生成的名称空间更改为我自己的名称空间.经过一番试验和磨难,我可以编译所有内容,而没有任何警告,错误或消息.该应用程序(随项目模板一起提供)运行良好.

I created a new Metro Split App in C++ using VS2012 on Win8 (both RC). Everything compiled and worked out of the box. I then changed went through and changed the generated namespaces to my own. After some trials and tribulations, I got everything to compile with no warnings, errors, nor messages. The app (as it comes in the project template) runs fine.

但是,如果我尝试编辑两个生成的xaml文件(ItemsPage.xaml或SplitPage.xaml),则第一行会出现标记错误":

However, if I try to edit either of the generated xaml files (ItemsPage.xaml or SplitPage.xaml) I get a "Markup error" on the first line:

名称空间"using:A.B.Product.Client.Common"中不存在名称"LayoutAwarePage".

The name "LayoutAwarePage" does not exist in the namespace "using:A.B.Product.Client.Common".

该类的定义是:

namespace A{ namespace B { namespace Product { namespace Client { namespace Common

代码可以正常编译,并且可以正常运行.这仅在设计模式下发生.

The code compiles fine, and runs fine. This only happens in design mode.

更新:我添加了一个新的xaml文件,并且(在再次修复名称空间之后)一切正常.

UPDATE: I added a new xaml file and (after fixing up the namespaces again) everything worked.

请让我知道是否需要其他信息.

Please let me know if any additional information is needed.

推荐答案

您的项目生成的WinMD文件的名称必须是在其中定义了公共WinRT类型的名称空间的某些前缀.假定您的类型位于A.B.Product.Client.Common命名空间中,则WinMD文件必须具有以下名称之一:

The name of the WinMD file produced by your project must be some prefix of the namespaces in which the public WinRT types are defined. Given that your type is in the A.B.Product.Client.Common namespace , the WinMD file must have one of the following names:

A.winmd
A.B.winmd
A.B.Product.winmd
A.B.Product.Client.winmd
A.B.Product.Client.Common.winmd

还必须在WinMD文件中使用与名称空间匹配的最长前缀定义公用类型.因此,如果同时具有 A.winmd A.B.winmd ,则必须在 A.B.winmd 中定义类型A.B.MyClass.

The public types must also be defined in the WinMD file with the longest prefix that matches the namespace. So, if you have both A.winmd and A.B.winmd, the type A.B.MyClass must be defined in A.B.winmd.

那么,为什么您的代码在运行时有效,而在设计器中却无法正常工作?公共类型的命名规则仅适用于Windows运行时组件(用于C ++,DLL文件)中定义的类型,不适用于应用程序(EXE).

So, why does your code work at runtime but not in the designer? The naming rules for public types only apply to types defined in Windows Runtime components (for C++, DLL files), not for applications (EXEs).

但是,为了能够实例化用户定义的类型(包括LayoutAwarePage),设计人员会将项目的EXE作为DLL加载,因此必须遵循命名规则.

However, to be able to instantiate your user-defined types (including LayoutAwarePage), the designer will load your project's EXE as a DLL, so the naming rules must be followed.

这篇关于XAML在本地名称空间中找不到引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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