It looks like the ContentDialog
is defined outside the context of the AppWindowPage
itself. Ideally, make sure that ContentDialog
is defined within the code-behind AppWindowPage.xaml.cs
, so it remains tied to the correct visual tree and dispatcher thread of the AppWindow
.
Also, you might want to update this line inside of ContentDialog
:
var dialog = new ContentDialog
{
...
XamlRoot = ViewsContext.XamlRoot//AppWindowPage XamlRoot.
...
};
await dialog.ShowAsync();
to:
var dialog = new ContentDialog
{
...
XamlRoot = this.XamlRoot
...
};
await dialog.ShowAsync();
This ensures that the dialog truly uses the XamlRoot
of the current page instance rather than relying on a static reference.
In addition, the OnNavigated
function in AppWindowPage
may be contributing to the issue. If ViewsContext.XamlRoot
is stale, delayed, or assigned too late, the ContentDialog
might not correctly anchor to the intended window’s visual tree. You can try to remove ViewsContext.XamlRoot = this.XamlRoot;
in OnNavigated
function to check that if it works.