gpt4 book ai didi

c# - Xamarin 表格 "...DisplayAlert does not exist in the current context."

转载 作者:太空狗 更新时间:2023-10-29 18:07:20 30 4
gpt4 key购买 nike

我正在使用 Xamarin,对它还是个新手,但我遇到了一个问题,我觉得我不应该这样。这是我的问题:

using System;
using Xamarin.Forms;

namespace DataBinding_Lists
{
public class App
{
public static Page GetMainPage ()
{
var listView = new ListView { RowHeight = 40 };
listView.ItemsSource = new Person []
{
new Person { FirstName = "Abe", LastName = "Lincoln" },
new Person { FirstName = "Groucho", LastName = "Marks" },
new Person { FirstName = "Carl", LastName = "Marks" },
};

listView.ItemTemplate = new DataTemplate(typeof(TextCell));
listView.ItemTemplate.SetBinding(TextCell.TextProperty, "FirstName");
listView.ItemSelected += async (sender, e) => {
await DisplayAlert ("Tapped!", e.SelectedItem + " was tapped.", "OK", "");
};

return new ContentPage {
Content = new StackLayout
{
Padding = new Thickness (5,20,5,5),
Spacing = 10,
Children = { listView }
}
};
}

}

显然,我在另一个名为“Person”的页面上有一个类。此类有两个属性:“FirstName”和“LastName”。当我尝试像在 Xamarin 中那样将所有这些放在一起时,我收到错误消息:“名称‘DisplayAlert’在当前上下文中不存在。”

最佳答案

或者只是尝试使用:

await App.Current.MainPage.DisplayAlert("Alert", "your message", "OK");

关于c# - Xamarin 表格 "...DisplayAlert does not exist in the current context.",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27497633/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com