UWP:在两个页面之间实现基本导航会导致错误

UWP: Implementing basic navigation between two pages results in an error?

本文关键字:实现 导航 错误 之间 两个 UWP      更新时间:2023-10-16

,所以我来自Windows表单,我正在尝试在Visual Studio 2017中创建一个UWP(通用Windows程序),用于运行Windows IoT的Raspberry Pi。我需要弄清楚如何使用程序创建多个窗口,因此我遵循Microsoft的本教程到TEE:https://learn.microsoft.com/en-us/windows/uwindows/UWP/uwp/design/basics/navigate-bettion - 两页。从理论上讲,它应该很好地编译,但这一切都返回:

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 "Page1.xaml.h"
#include "Page2.xaml.h"

在#include pch.h

下的所有.cpp文件上