Arush Agarampur
Arush Agarampur

Reputation: 1420

How to use navigate a frame when loading page from markup?

I have my XAML markup code for a Page <Page> written in a file page.xaml. I am using XamlReader::Load() to read my file - which succeeds. It saves it as a variable rootPage.

But the function Frame::Navigate<T>() takes a TypeName as T. I don't have the custom page class, I only have it saved as a variable. So how can I load that page and then navigate to it if the page is written in a XAML textfile?

Upvotes: 0

Views: 121

Answers (1)

Faywang - MSFT
Faywang - MSFT

Reputation: 5868

The first parameter of Navigate method needs to be passed as the type of page. You don't need to create the page instance, you just need to pass the type of page. You can use the winrt::xaml_typename() helper function to create a TypeName object about the page you want to navigate to. For example:

void MainPage::ClickHandler(IInspectable const&, RoutedEventArgs const&)
{
    Frame().Navigate(xaml_typename<page>());
}

For more details, you can refer to this document.

Upvotes: 1

Related Questions