【问题标题】:The name Display Alert does not exist in the current context?当前上下文中不存在名称显示警报?
【发布时间】:2017-11-20 22:19:20
【问题描述】:

我不知道为什么 DisplayAlert 不起作用,如果我写 page.Displayalert 它也不起作用

使用系统;

使用 Xamarin.Forms;

使用 UIKit;

命名空间 test.project { 公共部分类 ViewController : UIViewController {

    partial void UIButton197_TouchUpInside(UIButton sender)
    {
        if(textBoxName.Text == "" && textBoxpasswd.Text == "")
        {
            await displayAlert("Hello");
        }


    }

    protected ViewController(IntPtr handle) : base(handle)
    {
        // Note: this .ctor should not contain any initialization logic.
    }

    public override void ViewDidLoad()
    {
        base.ViewDidLoad();
        // Perform any additional setup after loading the view, typically from a nib.
    }

    public override void DidReceiveMemoryWarning()
    {
        base.DidReceiveMemoryWarning();
        // Release any cached data, images, etc that aren't in use.
    }
}

}

【问题讨论】:

  • DisplayAlert 是 Page 上的一个方法,一个 XF 类。您正在尝试从特定于 iOS 的 ViewController 中调用它。
  • 那我应该在哪里写呢?
  • 为什么要在 XF 项目中创建仅 iOS 页面?

标签: xamarin


【解决方案1】:

就像 Jason 说的,是 Page 上的一种方法,但如果你真的需要,你可以试试这个:

await App.Current.MainPage.DisplayAlert ("Hello", "No");

【讨论】:

    【解决方案2】:

    显示警报。这应该是 DisplayAlert。并且部分 void UIButton197_TouchUpInside 应该是异步的。

    【讨论】:

      猜你喜欢
      • 2013-10-02
      • 2014-04-22
      • 2017-06-17
      • 2015-09-11
      • 1970-01-01
      • 2010-10-20
      • 1970-01-01
      • 2022-12-18
      相关资源
      最近更新 更多