0

当有人试图关闭尚未保存的文件时,我正在尝试在我的 Windows RT 应用程序中启动保存对话框。但是,我不断收到0x80070005 - JavaScript runtime error: Access is denied错误消息

这是我使用启动消息对话框的代码。选择“不保存”(并BlankFile()运行)时,所有内容都运行正常。但是,当您选择“保存文件”时,它会在尝试运行时引发访问被拒绝错误.pickSaveFileAsync()

function createNewFile() 
{
    if (editedSinceSave)
    {
        // Create the message dialog and set its content 
        var msg = new Windows.UI.Popups.MessageDialog("Save this file?", 
            "Save Changes");

        // Add commands 
        msg.commands.append(new Windows.UI.Popups.UICommand("Don't Save", 
            function (command) {
                BlankFile();
            }));

        msg.commands.append(new Windows.UI.Popups.UICommand("Save File", 
            function (command) {
                //saveFile(true, true);
                testPop("test");
            }));

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

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

function testPop(text) {
    var msg = new Windows.UI.Popups.MessageDialog(text, "");
    msg.showAsync();
}
4

2 回答 2

1

您的核心问题是您要在另一个之上显示一个消息对话框。我在这里讨论细节和解决方案: Metro 应用程序中“警报”的替代方案是什么?

但是,您的流程自然需要发生这种情况——我建议考虑构建一种不同类型的流程,而不是堆叠对话框。

于 2013-01-09T01:35:47.377 回答
0

解决这个问题的方法似乎是设置一个命令 id 并在done()函数中捕获它showAsync(),就像这样

function createNewFile() 
{
    if (editedSinceSave)
    {
        // Add commands and set their CommandIds 
        msg.commands.append(new Windows.UI.Popups.UICommand("Dont Save", null, 1));
        msg.commands.append(new Windows.UI.Popups.UICommand("Save File", null, 2));

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

        // Show the message dialog 
        msg.showAsync().done(function (command) {
            if (command) {
                if (command.id == 1){
                    BlankFile();
                }
                else {
                    saveFile(true, true);
                }
            }
        });
    }
}

这不会引发任何错误。我不知道为什么以另一种方式这样做会引发错误,因为它似乎没有任何不同!

于 2013-01-08T21:50:08.677 回答