public LoginPage() { ViewModel.LoginFailed += HandleLoginFailed; ViewModel.LoginApproved += HandleLoginApproved; BackgroundColor = Color.FromHex("#3498db"); Padding = GetPagePadding(); _logo = new Image { Source = "xamarin_logo" }; _passwordEntry = new StyledEntry { Placeholder = "Password", IsPassword = true, ReturnType = ReturnType.Done }; _passwordEntry.SetBinding(Xamarin.Forms.Entry.TextProperty, nameof(LoginViewModel.PasswordEntryText)); _passwordEntry.SetBinding(Xamarin.Forms.Entry.ReturnCommandProperty, nameof(LoginViewModel.LoginButtonTappedCommand)); _logoSlogan = new StyledLabel { Opacity = 0, Text = "Delighting Developers.", }; _usernameEntry = new StyledEntry { Placeholder = "Username", ReturnType = ReturnType.Next, ReturnCommand = new Command(() => _passwordEntry.Focus()) }; _usernameEntry.SetBinding(Xamarin.Forms.Entry.TextProperty, nameof(LoginViewModel.UsernameEntryText)); _loginButton = new StyledButton(Borders.Thin) { Text = "Login" }; _loginButton.SetBinding(IsEnabledProperty, nameof(LoginViewModel.IsInternetConnectionInactive)); _loginButton.SetBinding(Button.CommandProperty, nameof(LoginViewModel.LoginButtonTappedCommand)); _newUserSignUpButton = new StyledButton(Borders.None) { Text = "Sign-up" }; _newUserSignUpButton.Clicked += HandleNewUserSignUpButtonClicked; _newUserSignUpButton.SetBinding(IsEnabledProperty, nameof(LoginViewModel.IsInternetConnectionInactive)); var activityIndicator = new ActivityIndicator { Color = Color.White }; activityIndicator.SetBinding(IsVisibleProperty, nameof(LoginViewModel.IsInternetConnectionActive)); activityIndicator.SetBinding(ActivityIndicator.IsRunningProperty, nameof(LoginViewModel.IsInternetConnectionActive)); On <Xamarin.Forms.PlatformConfiguration.iOS>().SetUseSafeArea(true); _relativeLayout = new RelativeLayout(); _relativeLayout.Children.Add(_logo, Constraint.Constant(100), Constraint.Constant(250), Constraint.RelativeToParent(parent => parent.Width - 200)); _relativeLayout.Children.Add(_logoSlogan, Constraint.RelativeToParent(parent => parent.Width / 2 - getWidth(parent, _logoSlogan) / 2), Constraint.Constant(125)); _relativeLayout.Children.Add(_usernameEntry, Constraint.Constant(40), Constraint.RelativeToView(_logoSlogan, (parent, view) => view.Y + view.Height + _relativeLayoutPadding), Constraint.RelativeToParent(parent => parent.Width - 80)); _relativeLayout.Children.Add(_passwordEntry, Constraint.Constant(40), Constraint.RelativeToView(_usernameEntry, (parent, view) => view.Y + view.Height + _relativeLayoutPadding), Constraint.RelativeToParent(parent => parent.Width - 80)); _relativeLayout.Children.Add(_loginButton, Constraint.Constant(40), Constraint.RelativeToView(_passwordEntry, (parent, view) => view.Y + view.Height + _relativeLayoutPadding), Constraint.RelativeToParent(parent => parent.Width - 80)); _relativeLayout.Children.Add(_newUserSignUpButton, Constraint.RelativeToParent(parent => parent.Width / 2 - getWidth(parent, _newUserSignUpButton) / 2), Constraint.RelativeToView(_loginButton, (parent, view) => view.Y + getHeight(parent, _loginButton) + 15)); _relativeLayout.Children.Add(activityIndicator, Constraint.RelativeToParent(parent => parent.Width / 2 - getWidth(parent, activityIndicator) / 2), Constraint.RelativeToParent(parent => parent.Height / 2 - getHeight(parent, activityIndicator) / 2)); Content = new Xamarin.Forms.ScrollView { Content = _relativeLayout };
protected override void OnAppearing() { base.OnAppearing(); Device.BeginInvokeOnMainThread(() => _usernameEntry.Focus()); }
public NewUserSignUpPage() { ViewModel.SaveFailed += HandleSaveFailed; ViewModel.TakePhotoFailed += HandleTakePhotoFailed; ViewModel.SaveSuccessfullyCompleted += HandleSaveSuccessfullyCompleted; BackgroundColor = Color.FromHex("2980b9"); var passwordEntry = new StyledEntry(1) { Placeholder = "Password", IsPassword = true, HorizontalOptions = LayoutOptions.Fill, HorizontalTextAlignment = TextAlignment.End, VerticalOptions = LayoutOptions.Fill, PlaceholderColor = Color.FromHex("749FA8"), ReturnType = ReturnType.Done }; passwordEntry.ReturnCommand = new Command(() => passwordEntry.Unfocus()); passwordEntry.SetBinding(Xamarin.Forms.Entry.TextProperty, nameof(NewUserSignUpViewModel.PasswordEntryText)); var usernameEntry = new StyledEntry(1) { Placeholder = "Username", HorizontalOptions = LayoutOptions.Fill, HorizontalTextAlignment = TextAlignment.End, PlaceholderColor = Color.FromHex("749FA8"), ReturnType = ReturnType.Next, ReturnCommand = new Command(() => passwordEntry.Focus()) }; usernameEntry.SetBinding(Xamarin.Forms.Entry.TextProperty, nameof(NewUserSignUpViewModel.UsernameEntryText)); _saveUsernameButton = new StyledButton(Borders.Thin, 1) { Text = "Save User", HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.EndAndExpand }; _saveUsernameButton.SetBinding(IsEnabledProperty, nameof(NewUserSignUpViewModel.IsInternetConnectionInactive)); _saveUsernameButton.SetBinding(Button.CommandProperty, nameof(NewUserSignUpViewModel.SaveButtonCommand)); _cancelButton = new StyledButton(Borders.Thin, 1) { Text = "Cancel", HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.End }; _cancelButton.Clicked += HandleCancelButtonClicked; _cancelButton.SetBinding(IsEnabledProperty, nameof(NewUserSignUpViewModel.IsInternetConnectionInactive)); _takePhotoButton = new StyledButton(Borders.Thin, 1) { Text = "Take Photo", HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.EndAndExpand }; _takePhotoButton.SetBinding(IsEnabledProperty, nameof(NewUserSignUpViewModel.IsInternetConnectionInactive)); _takePhotoButton.SetBinding(Button.CommandProperty, nameof(NewUserSignUpViewModel.TakePhotoButtonCommand)); var isFacialRecognitionCompletedDescriptionLabel = new StyledLabel { Text = "Facial Recognition Completed", VerticalTextAlignment = TextAlignment.Center }; var isFacialRecognitionCompletedLabel = new FontAwesomeIcon { TextColor = Color.White, VerticalTextAlignment = TextAlignment.Center, HorizontalTextAlignment = TextAlignment.Center }; isFacialRecognitionCompletedLabel.SetBinding(Label.TextProperty, nameof(NewUserSignUpViewModel.FontAwesomeLabelText)); if (Device.RuntimePlatform is Device.iOS) { isFacialRecognitionCompletedLabel.SetBinding(IsVisibleProperty, nameof(NewUserSignUpViewModel.IsInternetConnectionInactive)); } var activityIndicator = new ActivityIndicator { Color = Color.White, HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.EndAndExpand, }; activityIndicator.SetBinding(IsVisibleProperty, nameof(NewUserSignUpViewModel.IsInternetConnectionActive)); activityIndicator.SetBinding(ActivityIndicator.IsRunningProperty, nameof(NewUserSignUpViewModel.IsInternetConnectionActive)); var facialRecognitionStackLayout = new StackLayout { Orientation = StackOrientation.Horizontal, HorizontalOptions = LayoutOptions.Center, Children = { isFacialRecognitionCompletedDescriptionLabel, isFacialRecognitionCompletedLabel } }; var stackLayout = new StackLayout { Padding = new Thickness(20, 50, 20, 20), VerticalOptions = LayoutOptions.FillAndExpand, Children = { new Label { Text = "Please enter username", TextColor = Color.White, HorizontalOptions = LayoutOptions.Start }, usernameEntry, new Label { Text = "Please enter password", TextColor = Color.White, HorizontalOptions = LayoutOptions.Start }, passwordEntry, _takePhotoButton, facialRecognitionStackLayout, } }; switch (Device.RuntimePlatform) { case Device.iOS: facialRecognitionStackLayout.Children.Add(activityIndicator); break; case Device.Android: stackLayout.Children.Add(activityIndicator); break; default: throw new NotSupportedException("Device Runtime Unsupported"); } stackLayout.Children.Add(_saveUsernameButton); stackLayout.Children.Add(_cancelButton); Content = new Xamarin.Forms.ScrollView { Content = stackLayout }; On <Xamarin.Forms.PlatformConfiguration.iOS>().SetUseSafeArea(true); }