繁体   English   中英

如何从HTML5 Windows应用商店应用中的代码关闭MessageDialog?

[英]How can i close MessageDialog from code in HTML5 Windows Store app?

如标题所示,

如何从HTML5 Windows应用商店应用中的代码关闭MessageDialog?

我的代码到目前为止:

var msg = new Windows.UI.Popups.MessageDialog("Please wait");
msg.commands.append(new Windows.UI.Popups.UICommand("OK",
    function (command) {
        ...
    }));
msg.showAsync();

然后我想关闭这个弹出的FROM CODE,我还没有在规范中找到任何方法

msg.close();

有办法吗?

谢谢

您的消息是“请稍候”这一事实告诉我您可能想要使用不同的工具来完成这项工作。

如果您要做的是告知用户您正在后台执行他们需要等待的事情,请考虑使用Progress控件,如下所示:

http://msdn.microsoft.com/en-us/library/windows/apps/hh465487.aspx

如果使用“进度”控件,则可以包含带有所需文本的文本标签,并在完成要求用户等待的任何任务时关闭进度控件。

为了回答你原来的问题,我不相信有任何以编程方式解除MessageDialog的API,因为这会破坏此控件的交互模式,即应用程序显示消息,然后允许用户解除它当他们准备好的时候。

希望有所帮助。

有关Windows应用商店应用开发的更多信息,请注册App Builder

我想你想要使用弹出窗口,类似于这个答案 该链接解决了一个稍微不同的问题,因为它在超时后关闭弹出按钮。

但是,您应该能够定义您和用户可以关闭的弹出按钮。 在这两种情况下,您最终都会调用以下内容:

flyout.winControl.hide(); // Dismiss the flyout

看看这个...

(function(){
"use strict"; 
    var page = WinJS.UI.Pages.define("/html/cancelcommand.html", { 
        ready: function (element, options) { 
            document.getElementById("cancelCommand").addEventListener("click", cancelCommand_Click, false); 
        } 
    }); 

    // Click handler for the 'cancelCommand' button. 
    // Demonstrates setting the command to be invoked when the 'escape' key is pressed. 
    // Also demonstrates retrieval of the label of the chosen command and setting a callback to a function. 
    // A message will be displayed indicating which command was invoked. 
    // In this scenario, 'Try again' is selected as the default choice, and the 'escape' key will invoke the command named 'Close' 
    function cancelCommand_Click() { 
        // Create the message dialog and set its content 
        var msg = new Windows.UI.Popups.MessageDialog("No internet connection has been found."); 

        // Add commands and set their command handlers 
        msg.commands.append(new Windows.UI.Popups.UICommand("Try again", commandInvokedHandler)); 
        msg.commands.append(new Windows.UI.Popups.UICommand("Close", commandInvokedHandler)); 

        // Set the command that will be invoked by default 
        msg.defaultCommandIndex = 0; 

        // Set the command to be invoked when escape is pressed 
        msg.cancelCommandIndex = 1; 

        // Show the message dialog 
        msg.showAsync(); 
    } 

    function commandInvokedHandler(command) { 
        // Display message 
        WinJS.log && WinJS.log("The '" + command.label + "' command has been selected.", "sample", "status"); 
    } 
}());

http://code.msdn.microsoft.com/windowsapps/Message-dialog-sample-00c928f5/sourcecode?fileId=50972&pathId=1064922824

暂无
暂无

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

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