using MobileApp1.Services; using System; using System.Threading.Tasks; using Xamarin.Forms; using Xamarin.Forms.Xaml; namespace MobileApp1.Views { [XamlCompilation(XamlCompilationOptions.Compile)] public partial class LoginView : ContentView { protected bool isBusy = false; public LoginView() { InitializeComponent(); } private bool IsBusy { get => isBusy; set { isBusy = value; LoginPage cp = (LoginPage)ContentViewHelper.GetParentElement(this); if (cp != null) { cp.IsBusy = value; } Device.BeginInvokeOnMainThread(() => { loadingIndicatorView1.IsRunning = value; textbox1.IsEnabled = textbox2.IsEnabled = !value; button1.IsEnabled = !value; }); } } private async void button1_Clicked(object sender, EventArgs e) { await Task.Run(() => { if (this.Parent == null) { return; } ContentPage cp = ContentViewHelper.GetContentPage(this); if (cp == null) { return; } App ap = ContentViewHelper.GetApp(this); if (ap == null) { return; } this.IsBusy = true; ServiceResult result = ap.CorporationService.Login(textbox1.Text, textbox2.Text); loadingIndicatorView1.Message = result.Message; this.IsBusy = false; //await cp.DisplayAlert("Clicked", "Login", "OK"); if (result.IsSuccess) { /// part 2 } ContentViewHelper.SetMainPage(this, new MainPage()); }); } } }