0

以下のようなJavaScriptを使用してWindows8アプリケーションのポップアップメッセージを表示しています

var msg = new Windows.UI.Popups.MessageDialog("No internet connection has been found.");
msg.commands.append(new Windows.UI.Popups.UICommand("Try again", commandInvokedHandler));
msg.commands.append(new Windows.UI.Popups.UICommand("Close", commandInvokedHandler));
msg.defaultCommandIndex = 0;
msg.cancelCommandIndex = 1;
msg.showAsync();

ここで、ユーザーが何も入力していないため、しばらくしてからプログラムでポップアップメッセージを閉じたいと思います。

4

2 に答える 2

2

そのようなメッセージポップアップには、hide / dismiss/cancelコマンドはないと思います。キーボードのEscキーを押すと、キャンセルコマンドが呼び出されます。これらの種類のメッセージは、情報提供を目的としたものではありません。代わりに「FlyOut」を使用する必要があります。

HTML:

<!-- Define a flyout in HTML as you wish -->
<div id="informationFlyout" data-win-control="WinJS.UI.Flyout">
    <p>
        Some informative text
    </p>
</div>

<!-- an anchor for the flyout, where it should be displayed -->
<div id="flyoutAnchor"></div>

JS:

    // Get an anchor for the flyout
    var flyoutAnchor = document.getElementById("flyoutAnchor"); 

    // Show flyout at anchor
    document.getElementById("informationFlyout").winControl.show(flyoutAnchor); 

設定された時間が経過した後にフライアウトを閉じるには、setTimeoutを実行して、コード内に非表示にすることができます。

// execute this code after 2000ms
setTimeout(function () {

    // Fetch the flyout
    var flyout = document.getElementById("informationFlyout"); // Get the flyout from HTML

    // Check if the element still exists in DOM
    if (flyout) 
        flyout.winControl.hide(); // Dismiss the flyout

}, 2000); 

FlyOut-ポップアップについて詳しくはこちらをご覧ください

于 2012-07-26T12:00:43.117 に答える
1

実際には、showAsyncメソッドによって返されたオブジェクトに対して呼び出すことができるキャンセルがあります。最初に次のようにmessageDialogを呼び出します。

var msg = new Windows.UI.Popups.MessageDialog("No internet connection has been found.");
var asyncOperation = msg.showAsync();

その後、いつでも電話をかけることができます:

asyncOperation.cancel();

そしてmessageDialogは却下されます。

于 2014-01-06T09:25:53.547 に答える