Skip to content

Migrating UWP app to WindowsAppSDK. Can't navigate to page from Windows Runtime Component #1769

Open
@timmarriott

Description

@timmarriott

Describe the bug

Internal bug https://task.ms/36925415

App.xaml.cpp is just activates the MainWindow which is exactly what it does out of the box. I attempted to put the page navigation code in there as documented but didn't work. Now MainWindow.xaml had a named <Frame x:Name="rootFrame Loaded="Loaded"/>

In the Loaded Event for the Frame I am calling rootFrame().Navigate(xaml_typenameComponent::BlankPage(), *this);

In either case I get an exception thrown:
Exception thrown at 0x00007FFB4621466C (KernelBase.dll) in CloudView.exe: WinRT originate error - 0x80004005 : 'Cannot locate resource from 'ms-appx:///BlankPage.xaml'.'.

This is a project added as a WinUI3 Runtime Component inside the Solution. My production code is in a Separate solution and has the same problem.

I tried the same thing using the Windowing Sample cpp-winui from the WindowsAppSDK-Samples.git repo. It works there. The difference is that this uses a separate Packaging Project. The current SDK integrates the packaging into the App.

Steps to reproduce the bug

  1. Create a new Solution/Project using the "Blank App, Packaged (WinUI 3 in Desktop), Default names are fine. Don't check Solution in same folder

  2. Add a New Project to the Solution using the "Windows Runtime Component (WinUI 3)" template. Default names are fine.

  3. Add a New Item to the RuntimeComponent1 Project, using the "Blank Page (WinUI 3)" template. Default names are fine.

  4. Build the RuntimeComponent1. Debug, x64 is what I used.

  5. Add a Reference in App1 to RuntimeComponent1. Right click>Add>Reference...

  6. Edit MainWindow.xaml and make it look like this:


  7. Edit MainWindow.xaml.h.
    Add the following #includes above #include "MainWindow.g.h"
    #include <winrt/RuntimeComponent1.h>
    #include <winrt/Windows.UI.Xaml.Interop.h>
    Add the following Loaded Method
    void MainWindow::Loaded(Windows::Foundation::IInspectable sender, Microsoft::UI::Xaml::RoutedEventArgs const& e)
    {
    rootFrame().Navigate(xaml_typename < RuntimeComponent1::BlankPage>(), *this);
    }

  8. Edit MainWindow.xaml.cpp and remove the reference to myButton() in the myButton_Click Event.

  9. Build and run App1. You will get the exception.

Expected behavior

No response

Screenshots

No response

NuGet package version

1.0.0-preview3

Packaging type

Packaged (MSIX)

Windows version

Windows 11 (22000)

IDE

Visual Studio 2022

Additional context

No response

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions