Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
647 views
in Technique[技术] by (71.8m points)

windows 8 - XAML cannot find reference in local namespace

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.

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:

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

The definition of the class is:

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

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

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

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.

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).

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...