public ListViewItem() { ControlValidation = null; Content = new Grid { ColumnSpacing = 0, RowSpacing = 0, HorizontalOptions = LayoutOptions.Fill, VerticalOptions = LayoutOptions.CenterAndExpand, }; }
protected void RecreatControl() { _grid.Children.Clear(); _grid.RowDefinitions.Clear(); _grid.ColumnDefinitions.Clear(); _grid.RowSpacing = 0; ControlValidation = null; var listControl = GetParentListView(); if (listControl == null) { return; } var domainModelType = listControl.GetListItemType(); var attrib = domainModelType.GetAttribute <AutoFormsListUIAttribute>(); if (attrib == null) { return; } _grid.ColumnSpacing = attrib.ColumnSpacing; _grid.Padding = new Thickness(attrib.ListItemPaddingLeft, attrib.ListItemPaddingTop, attrib.ListItemPaddingRight, attrib.ListItemPaddingBottom); var props = AttributeHelper.GetPropertyAttributes <AutoFormsListItemAttribute>(domainModelType); ControlValidation controlValidation = new ControlValidation(() => { _grid.ForceLayout(); }); foreach (var p in props) { var property = p.Item1; var attribute = ControlBase.GetFilteredAttribute(listControl.Filter, p.Item2); if (property == null || attribute == null) { continue; } _grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(attribute.Value, attribute.GridType) }); var v = CreateControlView(property, attribute, listControl); //v.BackgroundColor = Color.Red; Grid.SetColumn(v, _grid.ColumnDefinitions.Count - 1); _grid.Children.Add(v); var validations = property.GetAttributes <AutoFormsValidationAttribute>(); if (validations != null && validations.Length > 0) { foreach (var validation in validations) { controlValidation.AddValidation(validation, v, string.IsNullOrWhiteSpace(attribute.Label) ? attribute.Placeholder : attribute.Label); } } } CreateActionButtons(attrib, listControl); if (controlValidation.Size > 0) { _grid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto }); Grid.SetRow(controlValidation, 1); Grid.SetColumnSpan(controlValidation, _grid.ColumnDefinitions.Count); _grid.Children.Add(controlValidation); ControlValidation = controlValidation; } //_grid.DebugGrid(Color.Green); }