demo-xf-app-1a/MobileApp1/Views/Content/Login/LoginView.xaml.cs

86 lines
2.0 KiB
C#

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 = ContentViewHelper.GetContentPage<LoginPage>(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;
//ContentViewHelper.SetMainPage(this, new AppShell());
//await cp.DisplayAlert("Clicked", "Login", "OK");
if (result.IsSuccess)
{
/// part 2
}
});
}
}
}