在哪里放置和如何调用几个Xamarin Forms页面共同的方法?



如果我想写一个方法,我可以从任何我的Xamarin Forms页面的代码调用,这将能够做的事情在UI -一个具体的弹出窗口-我在哪里把方法(应用程序?AppShell?),我该怎么称呼它?

VS 2019 Windows。Xamarin表单应用程序从新解决方案弹出模板创建。

您可以在App.xaml.cs中定义一个方法,下面是显示alertdialog的示例:

inApp.xaml.cs:

public static async void Alert()
{
await App.Current.MainPage.DisplayAlert("Warning", "this is a alert", "Cancel");
}

调用其他页面:

App.Alert();

最新更新