简体   繁体   English

正确的UWP AppWindow上的ContentDialog

[英]ContentDialog on correct UWP AppWindow

I am experimenting with the new AppWindow that came with the Windows 10 1903 update for creating multi-windowed UWP applications that use same UI-thread. 我正在尝试使用Windows 10 1903更新附带的新AppWindow来创建使用相同UI线程的多窗口UWP应用程序。

I am having an issue where I cannot get a ContentDialog to be modal on the second window. 我遇到了一个问题,我无法在第二个窗口中将ContentDialog设置为模态。 Microsoft's documentation states the following: "MessageDialog will not be modal to the correct window, recommendation is to use ContentDialog instead." Microsoft的文档声明如下:“MessageDialog不是模态到正确的窗口,建议改为使用ContentDialog。” However, it is not explained how this is achieved... 但是,没有解释如何实现这一目标......

Source: https://docs.microsoft.com/en-us/uwp/api/windows.ui.windowmanagement.appwindow 资料来源: https//docs.microsoft.com/en-us/uwp/api/windows.ui.windowmanagement.appwindow

Would anyone know how the get the ContentDialog to be modal on the correct Window? 有谁知道如何在正确的窗口上获取ContentDialog模态?

Thank you for reporting this, we will fix the documentation for ContentDialog. 感谢您报告此事,我们将修复ContentDialog的文档。

To open the ContentDialog on the correct window, you'll need to set the ContentDialog's XamlRoot property to the same XamlRoot as an element in the AppWindow. 要在正确的窗口上打开ContentDialog,您需要将ContentDialog的XamlRoot属性设置为与AppWindow中的元素相同的XamlRoot。

noWifiDialog.XamlRoot = elementAlreadyInTheAppWindow.XamlRoot;

Note that there is also a known limitation where only one ContentDialog can be open per thread at a time - meaning the app can't show a modal dialog in two windows on the same thread. 请注意,还有一个已知的限制,即每次只能为每个线程打开一个ContentDialog - 这意味着应用程序无法在同一个线程的两个窗口中显示模式对话框。 In this scenario, opening the second dialog will throw an exception which you'll need to try/catch. 在这种情况下,打开第二个对话框将抛出一个您需要尝试/捕获的异常。

The WinUI bug: Only one ContentDialog can be open per thread (even with multiple AppWindows) #794 WinUI错误: 每个线程只能打开一个ContentDialog(即使有多个AppWindows)#794

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM