我创建了随机JSON数据拾取器,我想显示拾取的数据,它在MAUI社区工具包Popop..代码:
private async void OnButton_Clicked1(object sender, EventArgs e)
{
Random random = new Random();
int randomdrink = random.Next(1, 5);
using var stream = await FileSystem.OpenAppPackageFileAsync("drinks.json");
using var reader = new StreamReader(stream);
var drinks = JsonSerializer.Deserialize<List<drinksclass>>(stream);
if (drinks != null)
{
this.ShowPopup(new PopupPageAlert(drinks.First(x => x.id == randomdrink)));
}
}
弹出代码:
public partial class PopupPageAlert : Popup
{
public drinksclass drink { get; set; }
public PopupPageAlert(drinksclass drink)
{
InitializeComponent();
this.drink = drink;
this.BindingContext = this.drink;
}
private void CloseBtn_Clicked(object sender, EventArgs e)
{
this.Close();
}
1条答案
按热度按时间bogh5gae1#
您可以通过构造函数传递参数,就像传递任何C#类一样
然后在弹出页面的构造函数中
然后在XAML中