I'm trying to create secondary window using new APIs like in this article: https://docs.microsoft.com/en-us/windows/uwp/design/layout/app-window
In general, it works except that it is impossible to track windows using dictionary like it was shown in that article, because UIContext of created AppWindow does not match UIContext of the Page hosted within that window. Is it some known bug or I do it wrong?
The code:
public class OpenInNewWindowCommand : DependencyObject, ICommand
{
...
public async void Execute(object parameter)
{
var pageName = Page;
if (!string.IsNullOrEmpty(pageName))
{
var pageType = Assembly.GetEntryAssembly().GetTypes().FirstOrDefault(t => t.IsClass && t.Name == pageName);
if (pageType != null)
{
var window = await AppWindow.TryCreateAsync();
var frame = new Frame();
ElementCompositionPreview.SetAppWindowContent(window, frame);
if (RequestedDisplayRegion != null) window.RequestMoveToDisplayRegion(RequestedDisplayRegion);
if (RequestedSize != Size.Empty) window.RequestSize(RequestedSize);
if (ExtendViewIntoTitleBar) TitleBarHelper.ExtendView(window);
var viewsService = Container.Instance.Resolve<IViewsServiceBase>();
viewsService.RegisterAppWindow(window);
window.Closed += (s, e) => { frame.Content = null; };
frame.Navigate(pageType, Parameter);
await window.TryShowAsync();
}
}
}
}
Debugging this on Windows 10 20H2, target and minimal versions are both set to 2004