void ConstructUI() { _layout = new StackLayout { Padding = new Thickness(20, 50, 20, 20), VerticalOptions = LayoutOptions.FillAndExpand, }; _usernameEntry = new StyledEntry(1) { Style = StyleConstants.UnderlinedEntry, AutomationId = AutomationIdConstants.NewUserSignUpPage_NewUserNameEntry, Placeholder = "Username", HorizontalOptions = LayoutOptions.Fill, HorizontalTextAlignment = TextAlignment.End, PlaceholderColor = Color.FromHex("749FA8"), ReturnType = ReturnType.Next, ReturnCommand = new Command(() => _passwordEntry.Focus()) }; _passwordEntry = new StyledEntry(1) { Style = StyleConstants.UnderlinedEntry, AutomationId = AutomationIdConstants.NewUserSignUpPage_NewPasswordEntry, Placeholder = "Password", IsPassword = true, HorizontalOptions = LayoutOptions.Fill, HorizontalTextAlignment = TextAlignment.End, VerticalOptions = LayoutOptions.Fill, PlaceholderColor = Color.FromHex("749FA8"), ReturnType = ReturnType.Go, ReturnCommand = new Command(() => HandleSaveUsernameButtonClicked(_saveUsernameButton, EventArgs.Empty)) }; _saveUsernameButton = new StyledButton(Borders.Thin, 1) { Style = StyleConstants.BorderedButton, AutomationId = AutomationIdConstants.NewUserSignUpPage_SaveUsernameButton, Text = "Save Username", HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.EndAndExpand }; _saveUsernameButton.Clicked += HandleSaveUsernameButtonClicked; _cancelButton = new StyledButton(Borders.Thin, 1) { Style = StyleConstants.BorderedButton, AutomationId = AutomationIdConstants.NewUserSignUpPage_CancelButton, Text = "Cancel", HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.End }; _cancelButton.Clicked += (object sender, EventArgs e) => { Navigation.PopModalAsync(); }; }
public NewUserSignUpPage() { On <iOS>().SetUseSafeArea(true); BackgroundColor = Color.FromHex("#2980b9"); _usernameEntry = new UnderlinedEntry("Username", AutomationIdConstants.NewUserSignUpPage_NewUserNameEntry) { ReturnType = ReturnType.Next }; _passwordEntry = new UnderlinedEntry("Password", AutomationIdConstants.NewUserSignUpPage_NewPasswordEntry) { IsPassword = true, ReturnType = ReturnType.Go, ReturnCommand = new Command(() => HandleSaveUsernameButtonClicked(_saveUsernameButton, EventArgs.Empty)) }; _saveUsernameButton = new BorderedButton("Save Username", AutomationIdConstants.NewUserSignUpPage_SaveUsernameButton) { HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.EndAndExpand }; _saveUsernameButton.Clicked += HandleSaveUsernameButtonClicked; _cancelButton = new BorderedButton("Cancel", AutomationIdConstants.NewUserSignUpPage_CancelButton) { HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.End }; _cancelButton.Clicked += (object sender, EventArgs e) => { Navigation.PopModalAsync(); }; var layout = new StackLayout { Padding = new Thickness(20, 50, 20, 20), VerticalOptions = LayoutOptions.FillAndExpand, Children = { new WhiteTextLabel("Please enter username"), _usernameEntry, new WhiteTextLabel("Please enter password"), _passwordEntry, _saveUsernameButton, _cancelButton } }; Content = new Xamarin.Forms.ScrollView { Content = layout }; }
protected override void OnElementChanged(ElementChangedEventArgs <Entry> e) { base.OnElementChanged(e); _styledElement = _styledElement ?? (Element as StyledEntry); if (Control != null) { if (_textStyle == null) { _textStyle = (!string.IsNullOrEmpty(_styledElement.TextStyleInstance) && TextStyle.Instances.ContainsKey(_styledElement.TextStyleInstance)) ? TextStyle.Instances [_styledElement.TextStyleInstance] : TextStyle.Main; } _styledElement.RawText = Control.Text; _textStyle.Style(Control, _styledElement.CssStyle, null, _styledElement.CustomTags); } }
void CreateGlobalChildren() { logo = new Image(); logoSlogan = new StyledLabel { Opacity = 0, Text = "Delighting Developers." }; loginEntry = new StyledEntry { AutomationId = AutomationIdConstants.UsernameEntry, Placeholder = "Username", }; CustomReturnEffect.SetReturnType(loginEntry, ReturnType.Next); CustomReturnEffect.SetReturnCommand(loginEntry, new Command(() => passwordEntry.Focus())); passwordEntry = new StyledEntry { AutomationId = AutomationIdConstants.PasswordEntry, Placeholder = "Password", IsPassword = true, }; CustomReturnEffect.SetReturnType(passwordEntry, ReturnType.Go); CustomReturnEffect.SetReturnCommand(passwordEntry, new Command(() => HandleLoginButtonClicked(passwordEntry, EventArgs.Empty))); loginButton = new StyledButton(Borders.Thin) { AutomationId = AutomationIdConstants.LoginButton, Text = "Login", }; newUserSignUpButton = new StyledButton(Borders.None) { AutomationId = AutomationIdConstants.NewUserButton, Text = "Sign-up", }; forgotPasswordButton = new StyledButton(Borders.None) { AutomationId = AutomationIdConstants.ForgotPasswordButton, Text = "Forgot Password?", }; loginButton.Clicked += HandleLoginButtonClicked; newUserSignUpButton.Clicked += (object sender, EventArgs e) => NewUserSignUp(); forgotPasswordButton.Clicked += (object sender, EventArgs e) => ForgotPassword(); }
void CreateGlobalChildren() { _logoSlogan = new StyledLabel { Opacity = 0, Text = "Delighting Developers." }; _loginEntry = new StyledEntry { AutomationId = AutomationIdConstants.LoginPage_UsernameEntry, Placeholder = "Username", }; CustomReturnEffect.SetReturnType(_loginEntry, ReturnType.Next); CustomReturnEffect.SetReturnCommand(_loginEntry, new Command(() => _passwordEntry.Focus())); _passwordEntry = new StyledEntry { AutomationId = AutomationIdConstants.LoginPage_PasswordEntry, Placeholder = "Password", IsPassword = true, }; CustomReturnEffect.SetReturnType(_passwordEntry, ReturnType.Go); CustomReturnEffect.SetReturnCommand(_passwordEntry, new Command(() => HandleLoginButtonClicked(_passwordEntry, EventArgs.Empty))); _loginButton = new StyledButton(Borders.Thin) { AutomationId = AutomationIdConstants.LoginPage_LoginButton, Text = "Login", }; _newUserSignUpButton = new StyledButton(Borders.None) { AutomationId = AutomationIdConstants.LoginPage_NewUserSignUpButton, Text = "Sign-up", }; _forgotPasswordButton = new StyledButton(Borders.None) { AutomationId = AutomationIdConstants.LoginPage_ForgotPasswordButton, Text = "Forgot Password?", }; }
public FirstPage() : base(PageTitleConstants.FirstPage) { const string entryTextPaceHolder = "Enter text and click 'Go'"; _goButton = new StyledButton(Borders.Thin, 1) { Text = "Go", AutomationId = AutomationIdConstants.GoButton, // This provides an ID that can be referenced in UITests }; _goButton.SetBinding(Button.CommandProperty, nameof(ViewModel.GoButtonCommand)); var textEntry = new StyledEntry(1) { Placeholder = entryTextPaceHolder, AutomationId = AutomationIdConstants.TextEntry, // This provides an ID that can be referenced in UITests PlaceholderColor = Color.FromHex("749FA8"), HorizontalTextAlignment = TextAlignment.Center }; CustomReturnEffect.SetReturnType(textEntry, ReturnType.Go); textEntry.SetBinding(CustomReturnEffect.ReturnCommandProperty, nameof(ViewModel.GoButtonCommand)); textEntry.SetBinding(Entry.TextProperty, nameof(ViewModel.EntryText)); var textLabel = new StyledLabel { AutomationId = AutomationIdConstants.TextLabel, // This provides an ID that can be referenced in UITests HorizontalOptions = LayoutOptions.Center }; textLabel.SetBinding(Label.TextProperty, nameof(ViewModel.LabelText)); _listPageButton = new StyledButton(Borders.Thin, 1) { Text = "Go to List Page", AutomationId = AutomationIdConstants.ListViewButton // This provides an ID that can be referenced in UITests }; var activityIndicator = new ActivityIndicator { AutomationId = AutomationIdConstants.BusyActivityIndicator, // This provides an ID that can be referenced in UITests Color = Color.White }; activityIndicator.SetBinding(IsVisibleProperty, nameof(ViewModel.IsActiityIndicatorRunning)); activityIndicator.SetBinding(ActivityIndicator.IsRunningProperty, nameof(ViewModel.IsActiityIndicatorRunning)); Func <RelativeLayout, double> getTextEntryWidth = (p) => textEntry.Measure(p.Width, p.Height).Request.Width; Func <RelativeLayout, double> getGoButtonWidth = (p) => _goButton.Measure(p.Width, p.Height).Request.Width; Func <RelativeLayout, double> getActivityIndicatorWidth = (p) => activityIndicator.Measure(p.Width, p.Height).Request.Width; Func <RelativeLayout, double> getTextLabelWidth = (p) => textLabel.Measure(p.Width, p.Height).Request.Width; var relativeLayout = new RelativeLayout(); relativeLayout.Children.Add(textEntry, Constraint.RelativeToParent((parent) => parent.X), Constraint.RelativeToParent((parent) => parent.Y), Constraint.RelativeToParent((parent) => parent.Width - 20)); relativeLayout.Children.Add(_goButton, Constraint.RelativeToParent((parent) => parent.X), Constraint.RelativeToView(textEntry, (parent, view) => view.Y + view.Height + _relativeLayoutPadding), Constraint.RelativeToParent((parent) => parent.Width - 20)); relativeLayout.Children.Add(activityIndicator, Constraint.RelativeToParent((parent) => parent.Width / 2 - getActivityIndicatorWidth(parent) / 2), Constraint.RelativeToView(_goButton, (parent, view) => view.Y + view.Height + _relativeLayoutPadding)); relativeLayout.Children.Add(textLabel, Constraint.RelativeToParent((parent) => parent.Width / 2 - getTextLabelWidth(parent) / 2), Constraint.RelativeToView(_goButton, (parent, view) => view.Y + view.Height + _relativeLayoutPadding)); relativeLayout.Children.Add(_listPageButton, Constraint.RelativeToParent((parent) => parent.X), Constraint.RelativeToView(_goButton, (parent, view) => view.Y + view.Height + _relativeLayoutPadding * 15), Constraint.RelativeToParent((parent) => parent.Width - 20)); Padding = GetPagePadding(); Content = relativeLayout; }
void CreateGlobalChildren() { logo = new Image(); logoSlogan = new StyledLabel { Opacity = 0, Text = "Delighting Developers." }; loginEntry = new StyledEntry { AutomationId = AutomationIdConstants.UsernameEntry, Placeholder = "Username", ReturnType = ReturnType.Next }; loginEntry.Completed += (sender, e) => passwordEntry.Focus(); passwordEntry = new StyledEntry { AutomationId = AutomationIdConstants.PasswordEntry, Placeholder = "Password", IsPassword = true, }; passwordEntry.Completed += HandleLoginButtonClicked; loginButton = new StyledButton(Borders.Thin) { AutomationId = AutomationIdConstants.LoginButton, Text = "Login", }; newUserSignUpButton = new StyledButton(Borders.None) { AutomationId = AutomationIdConstants.NewUserButton, Text = "Sign-up", }; forgotPasswordButton = new StyledButton(Borders.None) { AutomationId = AutomationIdConstants.ForgotPasswordButton, Text = "Forgot Password?", }; rememberMe = new Label { Opacity = 0, Text = "Remember Me", TextColor = Color.White, FontFamily = Device.OnPlatform( iOS: "AppleSDGothicNeo-Light", Android: "Droid Sans Mono", WinPhone: "Comic Sans MS"), }; saveUsername = new Switch { AutomationId = AutomationIdConstants.SaveUsernameSwitch, IsToggled = true, Opacity = 0 }; loginButton.Clicked += HandleLoginButtonClicked; newUserSignUpButton.Clicked += (object sender, EventArgs e) => { NewUserSignUp(); }; forgotPasswordButton.Clicked += (object sender, EventArgs e) => { ForgotPassword(); }; }
void CreateGlobalChildren() { logo = new Image(); logoSlogan = new StyledLabel { Opacity = 0, Text = "Delighting Developers." }; loginEntry = new StyledEntry { AutomationId = AutomationIdConstants.UsernameEntry, Placeholder = "Username", }; passwordEntry = new StyledEntry { AutomationId = AutomationIdConstants.PasswordEntry, Placeholder = "Password", IsPassword = true, }; loginButton = new StyledButton(Borders.Thin) { AutomationId = AutomationIdConstants.LoginButton, Text = "Login", }; newUserSignUpButton = new StyledButton(Borders.None) { AutomationId = AutomationIdConstants.NewUserButton, Text = "Sign-up", }; forgotPasswordButton = new StyledButton(Borders.None) { AutomationId = AutomationIdConstants.ForgotPasswordButton, Text = "Forgot Password?", }; rememberMe = new Label { Opacity = 0, Text = "Remember Me", TextColor = Color.White, FontFamily = Device.OnPlatform( iOS: "AppleSDGothicNeo-Light", Android: "Droid Sans Mono", WinPhone: "Comic Sans MS"), }; saveUsername = new Switch { AutomationId = AutomationIdConstants.SaveUsernameSwitch, IsToggled = true, Opacity = 0 }; loginButton.Clicked += (object sender, EventArgs e) => { if (string.IsNullOrEmpty(loginEntry.Text) || string.IsNullOrEmpty(passwordEntry.Text)) { DisplayAlert("Error", "You must enter a username and password.", "Okay"); return; } Login(loginEntry.Text, passwordEntry.Text, saveUsername.IsToggled); }; newUserSignUpButton.Clicked += (object sender, EventArgs e) => { NewUserSignUp(); }; forgotPasswordButton.Clicked += (object sender, EventArgs e) => { ForgotPassword(); }; }
public void ConstructUI() { layout = new StackLayout { Padding = new Thickness(20, 50, 20, 20), VerticalOptions = LayoutOptions.FillAndExpand, }; usernameEntry = new StyledEntry(1) { Style = StyleConstants.UnderlinedEntry, AutomationId = AutomationIdConstants.NewUserNameEntry, Placeholder = "Username", HorizontalOptions = LayoutOptions.Fill, HorizontalTextAlignment = TextAlignment.End, PlaceholderColor = Color.FromHex("749FA8") }; passwordEntry = new StyledEntry(1) { Style = StyleConstants.UnderlinedEntry, AutomationId = AutomationIdConstants.NewPasswordEntry, Placeholder = "Password", IsPassword = true, HorizontalOptions = LayoutOptions.Fill, HorizontalTextAlignment = TextAlignment.End, VerticalOptions = LayoutOptions.Fill, PlaceholderColor = Color.FromHex("749FA8") }; saveUsernameButton = new StyledButton(Borders.Thin, 1) { Style = StyleConstants.BorderedButton, AutomationId = AutomationIdConstants.SaveUsernameButton, Text = "Save Username", HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.EndAndExpand }; cancelButton = new StyledButton(Borders.Thin, 1) { Style = StyleConstants.BorderedButton, AutomationId = AutomationIdConstants.CancelButton, Text = "Cancel", HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.End }; saveUsernameButton.Clicked += async(object sender, EventArgs e) => { var success = await DependencyService.Get <ILogin>().SetPasswordForUsername(usernameEntry.Text, passwordEntry.Text); if (success) { await Navigation.PopModalAsync(); } else { await DisplayAlert("Error", "You must enter a username and a password", "Okay"); } }; cancelButton.Clicked += (object sender, EventArgs e) => { Navigation.PopModalAsync(); }; }
protected ReusableLoginPage(string logoFileImageSource) { On <iOS>().SetUseSafeArea(true); BackgroundColor = Color.FromHex("#3498db"); Padding = GetPagePadding(); MainLayout = new RelativeLayout(); LogoFileImageSource = logoFileImageSource; _logoSlogan = new StyledLabel { Opacity = 0, Text = "Delighting Developers." }; _loginEntry = new StyledEntry { AutomationId = AutomationIdConstants.LoginPage_UsernameEntry, Placeholder = "Username", ReturnType = ReturnType.Next }; _passwordEntry = new StyledEntry { AutomationId = AutomationIdConstants.LoginPage_PasswordEntry, Placeholder = "Password", IsPassword = true, ReturnType = ReturnType.Go, ReturnCommand = new Command(() => HandleLoginButtonClicked(_passwordEntry, EventArgs.Empty)) }; _loginButton = new StyledButton(Borders.Thin) { AutomationId = AutomationIdConstants.LoginPage_LoginButton, Text = "Login", }; _loginButton.Clicked += HandleLoginButtonClicked; _newUserSignUpButton = new StyledButton(Borders.None) { AutomationId = AutomationIdConstants.LoginPage_NewUserSignUpButton, Text = "Sign-up", }; _newUserSignUpButton.Clicked += HandleNewUserSignUpButtonClicked; _forgotPasswordButton = new StyledButton(Borders.None) { AutomationId = AutomationIdConstants.LoginPage_ForgotPasswordButton, Text = "Forgot Password?", }; _forgotPasswordButton.Clicked += HandleForgotPasswordButtonClicked; MainLayout.Children.Add(_logo, Constraint.Constant(100), Constraint.Constant(250), Constraint.RelativeToParent(p => p.Width - 200)); MainLayout.Children.Add(_logoSlogan, Constraint.RelativeToParent(p => (p.Width / 2) - (getLogoSloganWidth(p) / 2)), Constraint.Constant(125)); MainLayout.Children.Add(_loginEntry, Constraint.Constant(40), Constraint.RelativeToView(_logoSlogan, (p, v) => v.Y + v.Height + _relativeLayoutPadding), Constraint.RelativeToParent(p => p.Width - 80)); MainLayout.Children.Add(_passwordEntry, Constraint.Constant(40), Constraint.RelativeToView(_loginEntry, (p, v) => v.Y + v.Height + _relativeLayoutPadding), Constraint.RelativeToParent(p => p.Width - 80)); MainLayout.Children.Add(_loginButton, Constraint.Constant(40), Constraint.RelativeToView(_passwordEntry, (p, v) => v.Y + v.Height + _relativeLayoutPadding), Constraint.RelativeToParent(p => p.Width - 80)); MainLayout.Children.Add(_newUserSignUpButton, Constraint.RelativeToParent(p => (p.Width / 2) - (getNewUserButtonWidth(p) / 2)), Constraint.RelativeToView(_loginButton, (p, v) => v.Y + _loginButton.Height + 15)); MainLayout.Children.Add(_forgotPasswordButton, Constraint.RelativeToParent(p => (p.Width / 2) - (getForgotButtonWidth(p) / 2)), Constraint.RelativeToView(_newUserSignUpButton, (p, v) => v.Y + _newUserSignUpButton.Height + _relativeLayoutPadding)); Content = new Xamarin.Forms.ScrollView { Content = MainLayout }; double getNewUserButtonWidth(RelativeLayout p) => _newUserSignUpButton.Measure(p.Width, p.Height).Request.Width; double getForgotButtonWidth(RelativeLayout p) => _forgotPasswordButton.Measure(p.Width, p.Height).Request.Width; double getLogoSloganWidth(RelativeLayout p) => _logoSlogan.Measure(p.Width, p.Height).Request.Width; }
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(ViewModel.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(ViewModel.UsernameEntryText)); _saveUsernameButton = new StyledButton(Borders.Thin, 1) { Text = "Save User", HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.EndAndExpand }; _saveUsernameButton.SetBinding(IsEnabledProperty, nameof(ViewModel.IsInternetConnectionInactive)); _saveUsernameButton.SetBinding(Button.CommandProperty, nameof(ViewModel.SaveButtonCommand)); _cancelButton = new StyledButton(Borders.Thin, 1) { Text = "Cancel", HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.End }; _cancelButton.Clicked += HandleCancelButtonClicked; _cancelButton.SetBinding(IsEnabledProperty, nameof(ViewModel.IsInternetConnectionInactive)); _cancelButton.SetBinding(Button.CommandProperty, nameof(ViewModel.CancelButtonCommand)); _takePhotoButton = new StyledButton(Borders.Thin, 1) { Text = "Take Photo", HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.EndAndExpand }; _takePhotoButton.SetBinding(IsEnabledProperty, nameof(ViewModel.IsInternetConnectionInactive)); _takePhotoButton.SetBinding(Button.CommandProperty, nameof(ViewModel.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(ViewModel.FontAwesomeLabelText)); if (Device.RuntimePlatform is Device.iOS) { isFacialRecognitionCompletedLabel.SetBinding(IsVisibleProperty, nameof(ViewModel.IsInternetConnectionInactive)); } var activityIndicator = new ActivityIndicator { Color = Color.White, HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.EndAndExpand, }; activityIndicator.SetBinding(IsVisibleProperty, nameof(ViewModel.IsInternetConnectionActive)); activityIndicator.SetBinding(ActivityIndicator.IsRunningProperty, nameof(ViewModel.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); }
public FirstPage() { const string entryTextPaceHolder = "Enter text and click 'Go'"; var viewModel = new FirstPageViewModel(); BindingContext = viewModel; _goButton = new StyledButton(Borders.Thin, 1) { Text = "Go", AutomationId = AutomationIdConstants.GoButton, // This provides an ID that can be referenced in UITests }; _goButton.SetBinding <FirstPageViewModel>(Button.CommandProperty, vm => vm.GoButtonTapped); var textEntry = new StyledEntry(1) { Placeholder = entryTextPaceHolder, AutomationId = AutomationIdConstants.TextEntry, // This provides an ID that can be referenced in UITests PlaceholderColor = Color.FromHex("749FA8"), ReturnType = ReturnType.Go }; textEntry.Completed += (sender, e) => viewModel?.GoButtonTapped?.Execute(null); textEntry.SetBinding <FirstPageViewModel>(Entry.TextProperty, vm => vm.EntryText); var textLabel = new StyledLabel { AutomationId = AutomationIdConstants.TextLabel, // This provides an ID that can be referenced in UITests HorizontalOptions = LayoutOptions.Center }; textLabel.SetBinding <FirstPageViewModel>(Label.TextProperty, vm => vm.LabelText); _listPageButton = new StyledButton(Borders.Thin, 1) { Text = "Go to List Page", AutomationId = AutomationIdConstants.ListViewButton // This provides an ID that can be referenced in UITests }; var activityIndicator = new ActivityIndicator { AutomationId = AutomationIdConstants.BusyActivityIndicator, // This provides an ID that can be referenced in UITests Color = Color.White }; activityIndicator.SetBinding <FirstPageViewModel>(ActivityIndicator.IsVisibleProperty, vm => vm.IsActiityIndicatorRunning); activityIndicator.SetBinding <FirstPageViewModel>(ActivityIndicator.IsRunningProperty, vm => vm.IsActiityIndicatorRunning); var stackLayout = new StackLayout { Children = { textEntry, _goButton, activityIndicator, textLabel, }, VerticalOptions = LayoutOptions.StartAndExpand, HorizontalOptions = LayoutOptions.CenterAndExpand }; var relativeLayout = new RelativeLayout(); relativeLayout.Children.Add(stackLayout, Constraint.RelativeToParent((parent) => { return(parent.X); }), Constraint.RelativeToParent((parent) => { return(parent.Y); }), Constraint.RelativeToParent((parent) => { return(parent.Width - 20); }), Constraint.RelativeToParent((parent) => { return(parent.Height / 2); }) ); relativeLayout.Children.Add(_listPageButton, Constraint.RelativeToParent((parent) => { return(parent.X); }), Constraint.Constant(250), Constraint.RelativeToParent((parent) => { return(parent.Width - 20); }) ); Padding = new Thickness(10, Device.OnPlatform(20, 0, 0), 10, 5); Title = "First Page"; Content = relativeLayout; }
public LoginPage() { try { ViewModel.LoginFailed += HandleLoginFailed; ViewModel.LoginApproved += HandleLoginApproved; BackgroundColor = Color.FromHex("#3498db"); Padding = GetPagePadding(); _logo = new Image { Source = "xamarin_logo" }; _logoSlogan = new StyledLabel { Opacity = 0, Text = "ABSENSI", }; _usernameEntry = new StyledEntry { Placeholder = "Username", ReturnType = ReturnType.Next, ReturnCommand = new Command(() => _passwordEntry.Focus()) }; _usernameEntry.SetBinding(Xamarin.Forms.Entry.TextProperty, nameof(ViewModel.UsernameEntryText)); _passwordEntry = new StyledEntry { Placeholder = "Password", IsPassword = true, ReturnType = ReturnType.Done }; _passwordEntry.SetBinding(Xamarin.Forms.Entry.TextProperty, nameof(ViewModel.PasswordEntryText)); _passwordEntry.SetBinding(Xamarin.Forms.Entry.ReturnCommandProperty, nameof(ViewModel.LoginButtonTappedCommand)); _loginButton = new StyledButton(Borders.Thin) { Text = "Login" }; _loginButton.SetBinding(IsEnabledProperty, nameof(ViewModel.IsInternetConnectionInactive)); _loginButton.SetBinding(Button.CommandProperty, nameof(ViewModel.LoginButtonTappedCommand)); _newUserSignUpButton = new StyledButton(Borders.None) { Text = "Sign-up" }; _newUserSignUpButton.Clicked += HandleNewUserSignUpButtonClicked; _newUserSignUpButton.SetBinding(IsEnabledProperty, nameof(ViewModel.IsInternetConnectionInactive)); _HomeAutomationButton = new StyledButton(Borders.None) { Text = "Home Automation" }; _HomeAutomationButton.Clicked += HandleHomeAutomationClicked; _HomeAutomationButton.SetBinding(IsEnabledProperty, nameof(ViewModel.IsInternetConnectionInactive)); var activityIndicator = new ActivityIndicator { Color = Color.White }; activityIndicator.SetBinding(IsVisibleProperty, nameof(ViewModel.IsInternetConnectionActive)); activityIndicator.SetBinding(ActivityIndicator.IsRunningProperty, nameof(ViewModel.IsInternetConnectionActive)); On <Xamarin.Forms.PlatformConfiguration.iOS>().SetUseSafeArea(true); Func <RelativeLayout, double> getNewUserButtonWidth = (p) => _newUserSignUpButton.Measure(p.Width, p.Height).Request.Width; Func <RelativeLayout, double> getLogoSloganWidth = (p) => _logoSlogan.Measure(p.Width, p.Height).Request.Width; Func <RelativeLayout, double> getActivityIndicatorHeight = (p) => activityIndicator.Measure(p.Width, p.Height).Request.Height; Func <RelativeLayout, double> getActivityIndicatorWidth = (p) => activityIndicator.Measure(p.Width, p.Height).Request.Width; _relativeLayout = new RelativeLayout(); _relativeLayout.Children.Add( _logo, xConstraint: Constraint.Constant(100), yConstraint: Constraint.Constant(250), widthConstraint: Constraint.RelativeToParent(p => p.Width - 200) ); _relativeLayout.Children.Add( _logoSlogan, xConstraint: Constraint.RelativeToParent(p => (p.Width / 2) - (getLogoSloganWidth(p) / 2)), yConstraint: Constraint.Constant(125) ); _relativeLayout.Children.Add( _usernameEntry, xConstraint: Constraint.Constant(40), yConstraint: Constraint.RelativeToView(_logoSlogan, (p, v) => v.Y + v.Height + _relativeLayoutPadding), widthConstraint: Constraint.RelativeToParent(p => p.Width - 80) ); _relativeLayout.Children.Add( _passwordEntry, xConstraint: Constraint.Constant(40), yConstraint: Constraint.RelativeToView(_usernameEntry, (p, v) => v.Y + v.Height + _relativeLayoutPadding), widthConstraint: Constraint.RelativeToParent(p => p.Width - 80) ); _relativeLayout.Children.Add( _loginButton, xConstraint: Constraint.Constant(40), yConstraint: Constraint.RelativeToView(_passwordEntry, (p, v) => v.Y + v.Height + _relativeLayoutPadding), widthConstraint: Constraint.RelativeToParent(p => p.Width - 80) ); _relativeLayout.Children.Add( _newUserSignUpButton, xConstraint: Constraint.RelativeToParent(p => (p.Width / 2) - (getNewUserButtonWidth(p) / 2)), yConstraint: Constraint.RelativeToView(_loginButton, (p, v) => v.Y + _loginButton.Height + 15) ); _relativeLayout.Children.Add( _HomeAutomationButton, xConstraint: Constraint.Constant(40), yConstraint: Constraint.RelativeToView(_newUserSignUpButton, (p, v) => v.Y + v.Height + _relativeLayoutPadding), widthConstraint: Constraint.RelativeToParent(p => p.Width - 80) ); _relativeLayout.Children.Add(activityIndicator, xConstraint: Constraint.RelativeToParent(parent => parent.Width / 2 - getActivityIndicatorWidth(parent) / 2), yConstraint: Constraint.RelativeToParent(parent => parent.Height / 2 - getActivityIndicatorHeight(parent) / 2)); Content = new Xamarin.Forms.ScrollView { Content = _relativeLayout }; } catch (Exception ec) { DisplayAlert("Error", ec.ToString(), "Ok"); } }