【发布时间】:2019-07-23 03:30:30
【问题描述】:
所以我来自 Windows 窗体,我正在尝试在 Visual Studio 2017 中为运行 Windows IOT 的树莓派创建一个 UWP(通用 Windows 程序)。我需要弄清楚如何用一个程序创建多个窗口,所以我按照微软的这个教程做了一个 tee:https://docs.microsoft.com/en-us/windows/uwp/design/basics/navigate-between-two-pages。从理论上讲,它应该编译得很好,但是,它会返回:
Error C2065 'Page2': undeclared identifier (page1.xaml.cpp)
Error C2653 'Page2': is not a class or namespace name (page1.xaml.cpp)
Error C2065 'Page1': undeclared identifier (page2.xaml.cpp)
Error C2065 'Page1': undeclared identifier NavApp1 (app.xaml.cpp)
Error C2653 'Page1': is not a class or namespace name (page2.xaml.cpp)
Error C2653 'Page1': is not a class or namespace name (app.xaml.cpp)
我的代码:(Page1.xaml.cpp):
#include "Page2.xaml.h" #include "pch.h" #include "Page1.xaml.h"
void NavApp1::Page1::HyperlinkButton_Click(Platform::Object^ sender,
Windows::UI::Xaml::RoutedEventArgs^ e)
{ this->Frame->Navigate(Windows::UI::Xaml::Interop::TypeName(Page2::typeid)); }
我的代码:(Page2.xaml.cpp):
#include "Page1.xaml.h" #include "pch.h" #include "Page2.xaml.h"
void NavApp1::Page2::HyperlinkButton_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{this->Frame->Navigate(Windows::UI::Xaml::Interop::TypeName(Page1::typeid));}
【问题讨论】:
-
#include 指令必须单独出现在一行中。并且 pch.h 必须始终首先包含。
-
它们包含在自己的行中,当我发布这个问题时,我只是以一种奇怪的方式对它们进行了格式化。 @HansPassant
标签: c++ uwp c++-cli win-universal-app windows-10-iot-core