private static Cell GetPickerRow(PickerRow pickerRow) { Grid grid = new Grid() { VerticalOptions = LayoutOptions.FillAndExpand, HorizontalOptions = LayoutOptions.FillAndExpand, Margin = new Thickness(15, 0, 15, 0), RowDefinitions = { new RowDefinition { Height = PlatformsConstants.RowHeight }, }, }; Label label = new Label { Text = pickerRow.Title.ToUpper(), HorizontalOptions = LayoutOptions.Start, VerticalOptions = LayoutOptions.Center, TextColor = CustomColors.LightSharkonColor, FontSize = PlatformsConstants.TableViewFieldLabelFontSize, }; Label pickerLabel = new Label { Text = pickerRow.Title.ToUpper(), HorizontalOptions = LayoutOptions.Start, VerticalOptions = LayoutOptions.Center, TextColor = CustomColors.LightSharkonColor, FontSize = PlatformsConstants.TableViewFieldLabelFontSize, }; Picker picker = new Picker() { HorizontalOptions = LayoutOptions.FillAndExpand, VerticalOptions = LayoutOptions.Center, TextColor = CustomColors.DarkSharkonColor, }; picker.ItemsSource = pickerRow.Items.DisplayItems; if (pickerRow.SelectedIndex == -1) { picker.SelectedIndex = 0; } else { picker.SelectedIndex = pickerRow.SelectedIndex; } picker.SelectedIndexChanged += (sender, e) => pickerRow.SelectedIndexChanged?.Invoke(sender, e); CustomEntry newFieldEntry = new CustomEntry() { HorizontalOptions = LayoutOptions.FillAndExpand, VerticalOptions = LayoutOptions.Center, Placeholder = "New " + pickerRow.Title, TextColor = CustomColors.DarkSharkonColor, FontSize = PlatformsConstants.TableViewFieldEntryFontSize, }; Image deleteFieldButton = new Image { HorizontalOptions = LayoutOptions.End, VerticalOptions = LayoutOptions.Center, Source = deleteImageSource, Aspect = Aspect.AspectFill, WidthRequest = 24, HeightRequest = 24, }; StackLayout editStack = new StackLayout { Orientation = StackOrientation.Horizontal, HorizontalOptions = LayoutOptions.FillAndExpand, VerticalOptions = LayoutOptions.Center, Margin = new Thickness(0, -5, 0, 0), Children = { newFieldEntry, deleteFieldButton, }, }; StackLayout pickerStack = new StackLayout { Orientation = StackOrientation.Vertical, VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.FillAndExpand, Spacing = 7, IsVisible = false, Children = { pickerLabel, editStack, }, }; StackLayout stackLayout = new StackLayout { Orientation = StackOrientation.Vertical, VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.FillAndExpand, Spacing = 7, Children = { label, picker, }, }; grid.Children.Add(stackLayout, 0, 0); grid.Children.Add(pickerStack, 0, 0); picker.SelectedIndexChanged += (sender, e) => { if (picker.SelectedIndex != -1 && picker.SelectedIndex == picker.Items.Count - 1) { Device.BeginInvokeOnMainThread(() => { pickerStack.IsVisible = true; stackLayout.IsVisible = false; newFieldEntry.Focus(); Action <object, EventArgs> CompletedAction = ((obj, eventArgs) => { if (!String.IsNullOrEmpty(newFieldEntry.Text)) { pickerRow.Items.AddItem(newFieldEntry.Text); picker.ItemsSource = pickerRow.Items.DisplayItems; picker.SelectedIndex = picker.Items.Count - 2; } else { if (pickerRow.SelectedIndex == -1) { picker.SelectedIndex = 0; } else { picker.SelectedIndex = pickerRow.SelectedIndex; } } stackLayout.IsVisible = true; pickerStack.IsVisible = false; picker.Focus(); }); newFieldEntry.Completed += (obj, eventArgs) => CompletedAction(obj, eventArgs); deleteFieldButton.GestureRecognizers.Add(new TapGestureRecognizer() { Command = new Command(() => { if (pickerRow.SelectedIndex == -1) { picker.SelectedIndex = 0; } else { picker.SelectedIndex = pickerRow.SelectedIndex; } newFieldEntry.Unfocus(); stackLayout.IsVisible = true; pickerStack.IsVisible = false; picker.Focus(); }) }); }); } }; CustomViewCell viewCell = new CustomViewCell() { View = grid, ShowSelection = false }; return(viewCell); }
private static Cell GetEntryRow(EditorRow editorRow) { Grid grid = new Grid() { VerticalOptions = LayoutOptions.FillAndExpand, HorizontalOptions = LayoutOptions.FillAndExpand, Margin = new Thickness(15, 0, 15, 0), RowDefinitions = { new RowDefinition { Height = PlatformsConstants.RowHeight }, }, }; Label label = new Label { Text = editorRow.Title.ToUpper(), HorizontalOptions = LayoutOptions.Start, VerticalOptions = LayoutOptions.Center, TextColor = CustomColors.LinkBlueColor, FontSize = PlatformsConstants.TableViewFieldLabelFontSize, }; CustomEntry entry = new CustomEntry { Text = editorRow.Text, HorizontalOptions = LayoutOptions.FillAndExpand, VerticalOptions = LayoutOptions.Center, Keyboard = editorRow.Keyboard, TextColor = CustomColors.DarkSharkonColor, FontSize = PlatformsConstants.TableViewFieldEntryFontSize, }; if (label.Text.Contains("EMAIL")) { entry.ValidationRegex = new Regex(@"\A(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)\Z", RegexOptions.IgnoreCase | RegexOptions.Compiled); } StackLayout stackLayout = new StackLayout { Orientation = StackOrientation.Vertical, VerticalOptions = LayoutOptions.FillAndExpand, HorizontalOptions = LayoutOptions.FillAndExpand, Spacing = 7, Children = { label, entry, }, }; grid.Children.Add(stackLayout, 0, 0); CustomViewCell viewCell = new CustomViewCell() { View = grid, ShowSelection = false }; TapGestureRecognizer labelTapGestureRecognizer = new TapGestureRecognizer() { Command = new Command((obj) => editorRow.RowTappedAction?.Invoke(null)), NumberOfTapsRequired = 1, }; label.GestureRecognizers.Add(labelTapGestureRecognizer); entry.Focused += (sender, e) => editorRow.OnFocusAction?.Invoke(e); entry.Unfocused += (sender, e) => editorRow.OnUnfocusAction?.Invoke(e); entry.TextChanged += (sender, e) => editorRow.TextChangedAction?.Invoke(sender, e); return(viewCell); }
private static Cell GetNameRow(NameRow nameRow) { Grid grid = new Grid() { ColumnSpacing = 10, VerticalOptions = LayoutOptions.FillAndExpand, HorizontalOptions = LayoutOptions.FillAndExpand, Margin = new Thickness(15, 0, 15, 0), RowDefinitions = { new RowDefinition { Height = 60 }, }, ColumnDefinitions = { new ColumnDefinition { Width = new GridLength(1, GridUnitType.Auto) }, new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }, }, }; Label label = new Label { Text = "NAME", HorizontalOptions = LayoutOptions.Start, VerticalOptions = LayoutOptions.Center, TextColor = CustomColors.LinkBlueColor, FontSize = PlatformsConstants.TableViewFieldLabelFontSize, }; CustomEntry entry = new CustomEntry { Text = nameRow.Text, HorizontalOptions = LayoutOptions.FillAndExpand, VerticalOptions = LayoutOptions.Center, Keyboard = Keyboard.Default, TextColor = CustomColors.DarkSharkonColor, FontSize = PlatformsConstants.TableViewFieldEntryFontSize, }; SvgImage profileImage = new SvgImage { Aspect = Aspect.AspectFill, ResourceName = "Icons/avatar.svg", VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Center, WidthRequest = 50, HeightRequest = 50, }; profileImage.Effects.Add(Effect.Resolve("BCReaderDemo.RoundCornersEffect")); RoundCornersEffect.SetCornerRadius(profileImage, 25); profileImage.GestureRecognizers.Add(new TapGestureRecognizer { NumberOfTapsRequired = 1, Command = new Command <object>((obj) => nameRow.AddImageAction?.Invoke(null)), }); StackLayout stackLayout = new StackLayout { Orientation = StackOrientation.Vertical, HorizontalOptions = LayoutOptions.FillAndExpand, VerticalOptions = LayoutOptions.Center, Spacing = 7, Children = { label, entry, }, }; grid.Children.Add(profileImage, 0, 0); grid.Children.Add(stackLayout, 1, 0); TapGestureRecognizer labelTapGestureRecognizer = new TapGestureRecognizer() { Command = new Command((obj) => nameRow.RowTappedAction?.Invoke(null)), NumberOfTapsRequired = 1, }; label.GestureRecognizers.Add(labelTapGestureRecognizer); entry.Focused += (sender, e) => nameRow.OnFocusAction?.Invoke(e); entry.Unfocused += (sender, e) => nameRow.OnUnfocusAction?.Invoke(e); entry.TextChanged += (sender, e) => nameRow.TextChangedAction?.Invoke(sender, e); return(new CustomViewCell() { View = grid, ShowSelection = false }); }