namespace Blahblah.FlowerApp; public class AppContentPage : ContentPage { protected static string L(string key, string defaultValue = "") { return LocalizationResource.GetText(key, defaultValue); } protected static Task FetchAsync(string url, CancellationToken cancellation = default) { return Extensions.FetchAsync(url, cancellation); } protected T GetValue(BindableProperty property) { return (T)GetValue(property); } protected Task AlertError(string error) { return Alert(LocalizationResource.GetText("error", "Error"), error); } protected Task Alert(string title, string message, string? cancel = null) { cancel ??= LocalizationResource.GetText("ok", "Ok"); if (MainThread.IsMainThread) { return DisplayAlert(title, message, cancel); } var taskSource = new TaskCompletionSource(); MainThread.BeginInvokeOnMainThread(async () => { await DisplayAlert(title, message, cancel); taskSource.TrySetResult(); }); return taskSource.Task; } protected Task Confirm(string title, string question, string? accept = null, string? cancel = null) { accept ??= LocalizationResource.GetText("yes", "Yes"); cancel ??= LocalizationResource.GetText("no", "No"); if (MainThread.IsMainThread) { return DisplayAlert(title, question, accept, cancel); } var taskSource = new TaskCompletionSource(); MainThread.BeginInvokeOnMainThread(async () => { var result = await DisplayAlert(title, question, accept, cancel); taskSource.TrySetResult(result); }); return taskSource.Task; } }