【问题标题】:UWP: Implementing basic navigation between two pages results in an error?UWP:在两个页面之间实现基本导航会导致错误?
【发布时间】: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


【解决方案1】:

回答:我可以通过放置来解决这个问题

#include "Page1.xaml.h"
#include "Page2.xaml.h"

#include pch.h 下的所有 .cpp 文件

【讨论】:

    猜你喜欢
    • 2021-11-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-16
    • 1970-01-01
    • 2018-02-28
    相关资源
    最近更新 更多