检查是否显示特定的MessageDialog

时间:2015-11-10 19:26:20

标签: c# .net windows-runtime windows-store-apps win-universal-app

我想阻止一次显示2 MessageDialog s。所以我想只有一个MessageDialog并根据需要显示或隐藏它。但是,我无法找到如何检查它是否已经显示,并且调用ShowAsync两次会抛出异常。

那我如何检查它当前是否显示?

1 个答案:

答案 0 :(得分:1)

In that you (your code) control(s) the display of a dialog it is up to you to track whether it is being displayed.

You could set a flag somewhere in your code whenever the dialog is displayed that you can then check before showing it again.

psuedocode:

if (!dialogBeingShown)
{
    dialogBeingShown = true;

    await messageDialog.ShowAsync("alert");
    dialogBeingShown = false;
}

However, that you're asking this question suggests that your code is possibly overly complex such that you can get into the situation where different parts of the app may want to show messages at the same time. If this is really the case then an alternative method of displaying messages may be appropriate. Either way it sounds like it would be worth reviewing the logic in the app.