Skip to content

Instantly share code, notes, and snippets.

@julesx
Created July 14, 2017 17:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save julesx/03a3f85ad7105d24d0c667946a0053dd to your computer and use it in GitHub Desktop.
Save julesx/03a3f85ad7105d24d0c667946a0053dd to your computer and use it in GitHub Desktop.
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class LoginPage : ContentPage
{
public LoginPage()
{
InitializeComponent();
NavigationPage.SetHasNavigationBar(this, false);
BindingContext = Activator.CreateInstance(Globals.LoginPageViewModel);
UsernameEntry.Completed += (s, e) => PasswordEntry.Focus();
PasswordEntry.Completed += (s, e) => LoginButton.Command.Execute(null);
}
protected override void OnAppearing()
{
base.OnAppearing();
var loginPageViewModel = (LoginPageVm) BindingContext;
if (!string.IsNullOrWhiteSpace(loginPageViewModel.Username) && !string.IsNullOrWhiteSpace(loginPageViewModel.Password))
loginPageViewModel.CmdLogin.Execute(null);
else
UsernameEntry.Focus();
}
}
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Mobile.Core.Pages.LoginPage">
<Grid VerticalOptions="Fill" Margin="0,20,0,0">
<Grid.RowDefinitions>
<RowDefinition Height="5*" />
<RowDefinition Height="5*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="30" />
<ColumnDefinition />
<ColumnDefinition Width="30" />
</Grid.ColumnDefinitions>
<Image Grid.Row="0" Source="loginlogo.png" Grid.ColumnSpan="3" HorizontalOptions="Center" VerticalOptions="Center" />
<Grid WidthRequest="200" Grid.Row="1" Grid.Column="1" VerticalOptions="Center">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="30" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="10" />
<RowDefinition Height="65" />
</Grid.RowDefinitions>
<Label Grid.Row="0" Grid.Column="0" Margin="0,2" FontSize="24" Text="&#xf007;" FontFamily="FontAwesome" HorizontalOptions="Center" VerticalOptions="Center" />
<Entry x:Name="UsernameEntry" Grid.Row="0" Grid.Column="1" HeightRequest="40" Margin="0,2" Placeholder="Username" Text="{Binding Username}" Keyboard="Email" />
<Label FontSize="24" Grid.Row="1" Grid.Column="0" Margin="0,2" Text="&#xf023;" FontFamily="FontAwesome" HorizontalOptions="Center" VerticalOptions="Center" />
<Entry x:Name="PasswordEntry" Grid.Row="1" Grid.Column="1" HeightRequest="40" Margin="0,2" IsPassword="True" Placeholder="Password" Text="{Binding Password}" />
<ActivityIndicator IsRunning="{Binding LoggingIn}" Grid.Row="3" Grid.ColumnSpan="2" Grid.Column="0" VerticalOptions="Center" />
<Button Text="LOGIN" x:Name="LoginButton" FontSize="14" Grid.Row="3" Grid.ColumnSpan="2" Grid.Column="0" VerticalOptions="Center" StyleClass="Success"
Command="{Binding CmdLogin}" IsVisible="{Binding LoggingIn, Converter={StaticResource BoolInverter}}">
<Button.Style>
<Style TargetType="Button">
<Style.Triggers>
<DataTrigger TargetType="Button" Binding="{Binding IsEnabled, Source={x:Reference LoginButton}}" Value="False">
<Setter Property="TextColor" Value="White" />
</DataTrigger>
</Style.Triggers>
</Style>
</Button.Style>
</Button>
</Grid>
<Label Margin="0,0,0,10" Text="FORGOT PASSWORD" Grid.Row="2" FontSize="Small" HorizontalOptions="Center" VerticalOptions="Center" Grid.Column="0" Grid.ColumnSpan="3">
<Label.GestureRecognizers>
<TapGestureRecognizer Command="{Binding CmdForgotPassword}" />
</Label.GestureRecognizers>
<Label.TextColor>
<OnPlatform x:TypeArguments="Color">
<On Platform="iOS" Value="#17B6B1" />
<On Platform="Android" Value="Accent" />
</OnPlatform>
</Label.TextColor>
</Label>
</Grid>
</ContentPage>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment