StackLayout GetStepEntries(string labelText, string bindingPropRight, int n) { Label headLabel = new Label() { Text = labelText, HorizontalTextAlignment = TextAlignment.Center, VerticalTextAlignment = TextAlignment.Center, FontSize = 18, Margin = new Thickness(0, 0, 0, 10) }; RoundedBorderedEntry right = n == 1 ? GetEntry("Total de pares") : n == 2 ? GetEntry("Tempo de reação") : GetEntryText("Usuario"); right.SetBinding(RoundedEntry.TextProperty, new Binding(bindingPropRight)); StackLayout stack = new StackLayout() { Children = { headLabel, new StackLayout() { Orientation = StackOrientation.Horizontal, Children = { right } } }, Margin = 10 }; stack.BindingContext = ViewModel; return(stack); }
void ConfigureScreen() { //var navBar = ConfigureNavBar("Adicionar carro", true, true); var navBar = new StackLayout(); SearchEntry = new RoundedBorderedEntry() { CenteredPlaceholder = true, PlaceholderColor = ColorPalette.DarkBlue, Placeholder = "Qual o tipo do seu carro?".ToUpper(), FontAttributes = FontAttributes.Bold, FontSize = 15, TextColor = ColorPalette.DarkBlue, Padding = new Thickness(50, 30), BorderColor = ColorPalette.DarkBlue, BorderWidth = App.ScreenWidth / 72, HorizontalOptions = LayoutOptions.FillAndExpand, VerticalOptions = LayoutOptions.CenterAndExpand }; this.SearchEntry.SizeChanged += OnSearchSizeChanged; SearchIcon = new Icon() { Color = ColorPalette.DarkBlue, FileName = "search.svg", HeightRequest = 25, WidthRequest = 25, VerticalOptions = LayoutOptions.CenterAndExpand, HorizontalOptions = LayoutOptions.StartAndExpand, Margin = new Thickness(15, 0, 0, 0) }; SearchIcon.SetBinding(VisualElement.IsVisibleProperty, new Binding(nameof(SearchEntry.Text), source: SearchEntry, converter: new ValueConverter((text) => string.IsNullOrWhiteSpace((string)text)))); SearchGrid = new Grid() { HorizontalOptions = LayoutOptions.FillAndExpand, Margin = new Thickness(20, 30, 20, 30), }; SearchGrid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(50, GridUnitType.Absolute) }); SearchGrid.ColumnDefinitions.Add(new ColumnDefinition()); SearchGrid.Children.Add(SearchEntry, 0, 0); SearchGrid.Children.Add(SearchIcon, 0, 0); Label textSubtitleLabel = new Label() { Text = "Tipos populares", FontSize = 14, TextColor = ColorPalette.Gray, Margin = new Thickness(20, 0, 0, 0), HorizontalOptions = LayoutOptions.FillAndExpand }; RoundedBorderedLabel subtitleLabel = new RoundedBorderedLabel(textSubtitleLabel, Color.Transparent, 0, ColorPalette.ExtraLightGray, new Thickness(0, 5), 0) { HorizontalOptions = LayoutOptions.FillAndExpand }; subtitleLabel.Content.HorizontalOptions = subtitleLabel.HorizontalOptions; CarSelectionList optionsList = new CarSelectionList() { ItemsSource = ViewModel.TypeOptions, VerticalOptions = LayoutOptions.FillAndExpand, HorizontalOptions = LayoutOptions.FillAndExpand, }; optionsList.SetBinding(ListView.SelectedItemProperty, new Binding(nameof(ViewModel.SelectedType))); RoundedButton confirmatioButton = new RoundedButton() { BackgroundColor = ColorPalette.LightBlue, TextColor = Color.White, FontAttributes = FontAttributes.Bold, Text = "Continuar".ToUpper(), Margin = new Thickness(50, 0, 50, 30), FontSize = 17, VerticalOptions = LayoutOptions.End, Padding = new Thickness(10), Command = ViewModel.SelectOption }; Content = new StackLayout() { Children = { navBar, SearchGrid, SearchEntry, subtitleLabel, optionsList, confirmatioButton } }; }
private void ConfigureScreen() { NavBar = BaseContentPage.Instance.ConfigureNavBar("Carro personalizado".ToUpper(), true, true); NavBar.BackButton.GestureRecognizers.Clear(); NavBar.BackButton.GestureRecognizers.Add(new TapGestureRecognizer() { Command = new Command(() => { BaseContentPage.Instance.PopModal(); }) }); RoundedBorderedEntry car = GetEntryText("Marca"); car.SetBinding(RoundedEntry.TextProperty, new Binding($"{nameof(ViewModel.Car)}.{nameof(ViewModel.Car.Name)}")); RoundedBorderedEntry style = GetEntryText("Modelo"); style.SetBinding(RoundedEntry.TextProperty, new Binding($"{nameof(ViewModel.Car)}.{nameof(ViewModel.Car.Style)}")); RoundedBorderedEntry parkingSpace = GetEntry("Tamanho minimo de vaga (CM)"); parkingSpace.SetBinding(RoundedEntry.TextProperty, new Binding($"{nameof(ViewModel.Car)}.{nameof(ViewModel.Car.ParkingSpace)}", converter: Converter)); RoundedBorderedEntry wheelRadiusInt = GetEntry("Raio da roda Interno"); wheelRadiusInt.SetBinding(RoundedEntry.TextProperty, new Binding($"{nameof(ViewModel.Car)}.{nameof(ViewModel.Car.WheelRadiusInternal)}")); RoundedBorderedEntry wheelRadiusExt = GetEntryText("Raio da roda Externo"); wheelRadiusExt.SetBinding(RoundedEntry.TextProperty, new Binding($"{nameof(ViewModel.Car)}.{nameof(ViewModel.Car.WheelRadiusExternal)}")); Label passosDaBaliza = new Label() { FontSize = 16, Text = "Passos da baliza (em CM, sempre positivo)" }; StackLayout first = GetStepEntries("Primeiro passo - Centralizado/Frente", $"{nameof(ViewModel.Car)}.{nameof(ViewModel.Car.FirstLeft)}", $"{nameof(ViewModel.Car)}.{nameof(ViewModel.Car.FirstRight)}"); StackLayout second = GetStepEntries("Segundo passo - Esquerda/Trás", $"{nameof(ViewModel.Car)}.{nameof(ViewModel.Car.SecondLeft)}", $"{nameof(ViewModel.Car)}.{nameof(ViewModel.Car.SecondRight)}"); StackLayout third = GetStepEntries("Terceiro passo - Centralizado/Trás", $"{nameof(ViewModel.Car)}.{nameof(ViewModel.Car.ThirdLeft)}", $"{nameof(ViewModel.Car)}.{nameof(ViewModel.Car.ThirdRight)}"); StackLayout fourth = GetStepEntries("Quarto passo - Esquerda/Frente", $"{nameof(ViewModel.Car)}.{nameof(ViewModel.Car.FourthLeft)}", $"{nameof(ViewModel.Car)}.{nameof(ViewModel.Car.FourthRight)}"); StackLayout fifth = GetStepEntries("Quinto passo - Direita/Frente", $"{nameof(ViewModel.Car)}.{nameof(ViewModel.Car.FifthLeft)}", $"{nameof(ViewModel.Car)}.{nameof(ViewModel.Car.FifthRight)}"); StackLayout sixth = GetStepEntries("Sexto passo - Esquerda/Frente", $"{nameof(ViewModel.Car)}.{nameof(ViewModel.Car.SixthLeft)}", $"{nameof(ViewModel.Car)}.{nameof(ViewModel.Car.SixthRight)}"); var button = new Button() { Text = "Concluido", BackgroundColor = ColorPalette.LightBlue, TextColor = Color.White, BorderRadius = 18, Margin = 10, HeightRequest = 55, FontSize = 17, Command = ViewModel.Continue, }; Content = new StackLayout() { Children = { NavBar, car, style, parkingSpace, wheelRadiusExt, wheelRadiusInt, first, second, third, fourth, fifth, sixth, button } }; }
void ConfigureScreen() { NavBar = BaseContentPage.Instance.ConfigureNavBar("Adicionar carro", true); SearchEntry = new RoundedBorderedEntry() { CenteredPlaceholder = true, PlaceholderColor = ColorPalette.DarkBlue, Placeholder = "Qual a marca do seu carro?".ToUpper(), FontAttributes = FontAttributes.Bold, FontSize = 15, TextColor = ColorPalette.DarkBlue, BorderColor = ColorPalette.DarkBlue, BorderWidth = App.ScreenWidth / 72, HorizontalOptions = LayoutOptions.FillAndExpand, }; SearchIcon = new Icon() { HeightRequest = 25, WidthRequest = 25, VerticalOptions = LayoutOptions.CenterAndExpand, HorizontalOptions = LayoutOptions.StartAndExpand, Margin = new Thickness(15, 0, 0, 0), Color = ColorPalette.DarkBlue, FileName = "search.svg", }; SearchIcon.SetBinding(VisualElement.IsVisibleProperty, new Binding(nameof(SearchEntry.Text), source: SearchEntry, converter: new ValueConverter((text) => string.IsNullOrWhiteSpace((string)text)))); SearchGrid = new Grid() { HorizontalOptions = LayoutOptions.FillAndExpand, Margin = new Thickness(20, 30, 20, 30), }; SearchGrid.RowDefinitions.Add(new RowDefinition()); SearchGrid.ColumnDefinitions.Add(new ColumnDefinition()); Label textSubtitleLabel = new Label() { Text = "Marcas populares", FontSize = 14, TextColor = ColorPalette.Gray, Margin = new Thickness(20, 0, 0, 0), HorizontalOptions = LayoutOptions.FillAndExpand }; RoundedBorderedLabel subtitleLabel = new RoundedBorderedLabel(textSubtitleLabel, Color.Transparent, 0, ColorPalette.ExtraLightGray, new Thickness(0, 5), 0) { HorizontalOptions = LayoutOptions.FillAndExpand }; subtitleLabel.Content.HorizontalOptions = subtitleLabel.HorizontalOptions; int counter = 0; optionsList = new CarSelectionList() { ItemsSource = ViewModel.BrandOptions, VerticalOptions = LayoutOptions.FillAndExpand, HorizontalOptions = LayoutOptions.FillAndExpand, ItemTemplate = new DataTemplate(() => { var option = ViewModel.BrandOptions[counter]; CustomLabel label = new CustomLabel() { VerticalTextAlignment = TextAlignment.Center, CustomPadding = new Thickness(10, 0, 0, 0), Text = option.Name, FontSize = 16, TextColor = option == ViewModel.SelectedBrand ? ColorPalette.Pink : ColorPalette.Gray, FontAttributes = FontAttributes.Bold, BackgroundColor = Color.White }; CustomViewCell cell = new CustomViewCell(label) { View = label, SelectedTextColor = ColorPalette.Pink, NormalTextColor = label.TextColor, }; counter++; return(cell); }) }; optionsList.SetBinding(ListView.SelectedItemProperty, new Binding(nameof(ViewModel.SelectedBrand))); //optionsList.ItemTapped += ViewModel.OnItemTapped; if (App.IsAndroidSDKBelowMarshmallow) { optionsList.ItemSelected += (sender, args) => { ViewModel.SelectedBrand = args.SelectedItem as CarFilterInfo; optionsList.Layout(optionsList.Bounds); } } ; Button confirmatioButton = new Button() { BackgroundColor = ColorPalette.LightBlue, TextColor = Color.White, FontAttributes = FontAttributes.Bold, Text = "Continuar".ToUpper(), //Margin = new Thickness(50, 0, 50, 30), FontSize = 18, VerticalOptions = LayoutOptions.End, //Padding = new Thickness(10), BorderRadius = 18, Margin = 10, HeightRequest = 55, Command = ViewModel.SelectOption }; Children.Clear(); Children.Add(NavBar); Children.Add(SearchEntry); Children.Add(SearchGrid); Children.Add(subtitleLabel); Children.Add(optionsList); Children.Add(confirmatioButton); SearchEntry.SizeChanged += OnSearchSizeChanged; SearchEntry.Completed += OnTextChanged; }
StackLayout GetStepEntries(string labelText, string bindingPropLeft, string bindingPropRight) { Label headLabel = new Label() { Text = labelText, HorizontalTextAlignment = TextAlignment.Center, VerticalTextAlignment = TextAlignment.Center, FontSize = 18, Margin = new Thickness(0, 0, 0, 10) }; RoundedBorderedEntry left = GetEntry("Esquerda"); RoundedBorderedEntry right = GetEntry("Direita"); left.SetBinding(RoundedEntry.TextProperty, new Binding(bindingPropLeft)); right.SetBinding(RoundedEntry.TextProperty, new Binding(bindingPropRight)); StackLayout stack = new StackLayout() { Children = { headLabel, new StackLayout() { Orientation = StackOrientation.Horizontal, Children = { left, right } } }, Margin = 10 }; /* * if (App.IsAndroidSDKBelowMarshmallow) * { * * var propLeft = bindingPropLeft.Split('.')[1]; * var propRight = bindingPropRight.Split('.')[1]; * * ViewModel.PropertyChanged += (sender, args) => * { * if (args.PropertyName == propLeft) * left.Text = ViewModel.GetType().GetProperty(propLeft).GetValue(ViewModel).ToString(); * else if (args.PropertyName == propRight) * right.Text = ViewModel.GetType().GetProperty(propLeft).GetValue(ViewModel).ToString(); * }; * * left.TextChanged += (sender, args) => * { * double value = 0; * double.TryParse(left.Text, out value); * var viewmodelType = typeof(NewCarViewModel); * var prop = viewmodelType.GetProperty(propLeft); * prop.SetValue(ViewModel, value); * }; * * right.TextChanged += (sender, args) => * { * double value = 0; * double.TryParse(right.Text, out value); * var viewmodelType = typeof(NewCarViewModel); * var prop = viewmodelType.GetProperty(propRight); * prop.SetValue(ViewModel, value); * //ViewModel.GetType().GetProperty(propRight).SetValue(ViewModel, value); * }; * * } */ stack.BindingContext = ViewModel; return(stack); }