I have a WinUi3 app written in C++.
I want to show a "MessageBox" before displaying the main window of the application (only sometimes, and based on some switch received in command line).
I tried to put this code in App::OnLaunched() but it throws an Exception:
Exception thrown at 0x00007FFD661100AC (KernelBase.dll) in App1.exe: WinRT originate error - 0x80070057 : 'This element does not have a XamlRoot. Either set the XamlRoot property or add the element to a tree.'.
The code is:
window = make<MainWindow>();
window.Activate();
winrt::Microsoft::UI::Xaml::Controls::ContentDialog dialog;
dialog.Title(box_value(L"Modern Dialog"));
dialog.Content(box_value(L"WinUI 3 ContentDialog"));
dialog.CloseButtonText(L"OK");
dialog.XamlRoot(window.Content().XamlRoot());
dialog.ShowAsync();
How to make the ContentDialog display?