简体   繁体   中英

How to navigate to a new page using WinUI3 with C++ desktop app?

Firstly I create a project using template "Blank App, Packaged(WinUI in Desktop)" in Visual Studio.

Then I changed code in MainWindow.xaml to a simple Frame:

<Frame x:Name="rootFrame"></Frame>

And then I add a BlankPage and try to navigate to the BlankPage like this:

rootFrame().Navigate(xaml_typename<BlankPage>());

And then visual studio give me error:

winrt\Windows.UI.Xaml.Interop.h(643,29): error C2338: T must be WinRT type.

I don't know how to do...

Finally I found what's wrong. It's relate to namespace, when I create a new Page, there are three namespace:

winrt::PROJECTNAME::implementation::BlankPage
winrt::PROJECTNAME::factory_implementation::BlankPage
PROJECTNAME::BlankPage

I should use PROJECTNAME::BlankPage defined in BlankPage.idl

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM