Here is MainPage.xaml
.
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:vm="clr-namespace:App142"
x:Class="App142.MainPage">
<StackLayout>
<Grid
Padding="20"
RowDefinitions="120,Auto,*"
RowSpacing="20"
VerticalOptions="Center">
<Frame
Grid.Row="1"
Padding="0"
BorderColor="Silver"
IsClippedToBounds="True"
VerticalOptions="FillAndExpand">
<StackLayout Padding="20">
<Entry
Placeholder="Email"
Text="{Binding Users.Email}" />
<Entry
Placeholder="Password"
Text="{Binding Users.Password}" />
<Button Command="{Binding Login}" Text="Login"/>
</StackLayout>
</Frame>
<Label
Grid.Row="2"
HorizontalOptions="End"
Text="Do not ave an account? Sign up">
<Label.GestureRecognizers>
<TapGestureRecognizer Command="{Binding OpenRegisterPopupCommand}" />
</Label.GestureRecognizers>
</Label>
</Grid>
</StackLayout>
</ContentPage>
Here is MainPage.xaml.cs
. Contains ViewModel and User model.
using PropertyChanged;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using Xamarin.Forms;
namespace App142
{
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
BindingContext = new LoginPageViewModel();
}
}
[AddINotifyPropertyChangedInterface]
public class LoginPageViewModel
{
public ICommand OpenRegisterPopupCommand { get; set; }
public ICommand Register { get; set; }
public ICommand Login { get; set; }
public Users Users { get; set; }
public bool IsPopUpOpen { get; set; }
public LoginPageViewModel()
{
Users = new Users();
Users.PropertyChanged += OnUserEditPropertyChanged;
Login = new Command(LoginAction, LoginAllowd);
Register = new Command(RegisterAction);
OpenRegisterPopupCommand = new Command(() => {
IsPopUpOpen = true;
});
}
void OnUserEditPropertyChanged(object sender, PropertyChangedEventArgs args)
{
(Login as Command).ChangeCanExecute();
}
private bool LoginAllowd()
{
return !string.IsNullOrEmpty(Users.Email) && !string.IsNullOrEmpty(Users.Password);
}
private void LoginAction()
{
}
private void RegisterAction()
{
}
}
[AddINotifyPropertyChangedInterface]
public class Users: INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
public string Id { get; set; }
public string Email { get; set; }
public string Password { get; set; }
}
}