【问题标题】:Confirm() method for Windows UWPWindows UWP 的 Confirm() 方法
【发布时间】:2017-11-17 12:59:09
【问题描述】:

我正在使用 Cordova 开发一个应用程序,在某些时候我需要显示一个确认框,我对 android 使用 confirm() 方法,它可以工作。但是,它不适用于通用 Windows 平台 (UWP)。

我曾尝试使用名为MessageDialog() 的c# 方法并将其调用到JavaScript 中,并且效果很好。但是,它是一种异步方法,即它不会阻塞以下代码行。我也试过ContentDialog(),但它使应用程序崩溃

谁能帮助我解释如何使用 ContentDialog 或建议我可以使用的其他 JavaScript 或 c# 方法

【问题讨论】:

    标签: javascript c# windows cordova uwp


    【解决方案1】:

    安装cordova-plugin-dialogs

    cordova plugin add cordova-plugin-dialogs

    并使用navigator.notification.confirm(message, confirmCallback, [title], [buttonLabels])

    • 消息:对话消息。 (字符串)
    • confirmCallback:在按下按钮的索引(1、2 或 3)或在没有按下按钮(0)的情况下关闭对话框时调用的回调。 (函数)
    • title:对话框标题。 (字符串)(可选,默认为确认)
    • buttonLabels:指定按钮标签的字符串数组。 (数组)(可选,默认为 [OK,Cancel])

    完整示例:

    function onConfirm(buttonIndex) {
        alert('You selected button ' + buttonIndex);
    }
    
    navigator.notification.confirm(
        'You are the winner!', // message
         onConfirm,            // callback to invoke with index of button pressed
        'Game Over',           // title
        ['Restart','Exit']     // buttonLabels
    );
    

    【讨论】:

      【解决方案2】:
      using Windows.UI.Xaml.Controls;    
      ....
      
      public async void DisplayDialog(string title, string message)
      {
          ContentDialog SaveData = new ContentDialog
             {
                  Title = title,
                  Content = message,
                  CloseButtonText = "Ok"
             };
                 ContentDialogResult result = await SaveData.ShowAsync();
       }
      

      试试这个,这个代码对我有用。

      谢谢

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-04-20
        • 1970-01-01
        • 2016-11-14
        相关资源
        最近更新 更多