How do I open a new window in WinRT / WinUI3? I want to click a button and open up another floating window on top of the current / main window.
I have tried code from several samples with zero luck:
- https://learn.microsoft.com/en-us/windows/apps/windows-app-sdk/windowing/windowing-overview
- I can't import <winrt/Microsoft.UI.Windowing.h> (the dll does not load)
- https://github.com/microsoft/Windows-universal-samples/blob/main/Samples/AppWindow/cppwinrt/Scenario3_Size.h
- This uses the old Windows:: namespace (not appropriate)
- https://github.com/microsoft/WinUI-3-Demos/tree/master/src/ContosoAirlinePOS
- Does not navigate to a new window (BoardingPassWindow is actually a Page, not a Window)
Frame.Navigate(xaml_typename<NewWindowClass>())
- does not work / exception thrown
-
winrt::Microsoft::UI::Xaml::Controls::Frame rootFrame{ nullptr }; auto content = Window::Current().Content(); if (content) { rootFrame = content.try_as<winrt::Microsoft::UI::Xaml::Controls::Frame>(); }
- above snippet^
Window::Current().Content();
throws an exception when called
appWindow = Microsoft::UI::Xaml::Window(this, {}); appWindow.Activate()
- throws exception
The majority of the C++ WinUI3 documentation still only has C# code samples in it and is largely useless to me for that reason. I just want to open a new window and nothing else.
CreateInstance(winrt::Windows::Foundation::IInspectable const& baseInterface, winrt::Windows::Foundation::IInspectable& innerInterface)
with this code. I tried it with a 1.0.0 experimental project and it worked fine. – Denaturalize