【问题标题】:How can I call DisplayAlert in a Xamarin Forms application如何在 Xamarin Forms 应用程序中调用 DisplayAlert
【发布时间】:2019-11-12 01:25:39
【问题描述】:

我有一个视图模型,代码如下:

    public async Task StopBtnAsync()
    {
        CancelSpeech();
        App.pauseCard = true;
        if (Settings.mode == MO.Learn)
            StopLearn();
        if (Settings.mode == MO.Practice)
            StopPractice();
        if (Settings.mode == MO.Quiz)
        {
            if (await DisplayAlert("Stop Quiz " + Settings.quiz, "Please confirm", "OK", "Cancel") == true)
                StopQuiz();
        }

    }

单击停止按钮会尝试显示 DisplayAlert 进行确认。

但 DisplayAlert 在 IDE 中显示为红色,并显示一条消息,指出它在当前上下文中不存在。

注意,我尝试将其更改为:App.Current.MainPage.DisplayAlert 但这仍然不起作用。可能是因为这是一个 shell 应用程序。

谁能告诉我如何解决这个问题。

参考:

public partial class App : Application
{
    public App()
    {
        InitializeComponent();
        MainPage = new AppShell();
    }

【问题讨论】:

    标签: xamarin xamarin.forms


    【解决方案1】:

    DisplayAlertPage 类的一个方法,你需要做这样的事情

    Application.Current.MainPage.DisplayAlert
    

    【讨论】:

      猜你喜欢
      • 2019-10-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-26
      相关资源
      最近更新 更多