private void UpdateFields( FormDefinition formDefinition, INZazuWpfFieldFactory fieldFactory, IResolveLayout resolveLayout) { Dispose(); DisposeChecks(); // make sure at least the minimum is set for render the layout if (formDefinition?.Fields == null) { return; } CreateFields(formDefinition.Fields, fieldFactory); if (formDefinition.Checks != null) { CreateFormChecks(formDefinition.Checks, fieldFactory.Resolve <ICheckFactory>()); } var layout = resolveLayout.Resolve(formDefinition.Layout); var parentFields = FormDefinition.Fields.Select(fd => GetField(fd.Key)); layout.DoLayout(Layout, parentFields, resolveLayout); this.SetFieldValues(FormData.Values); SetReadOnly(IsReadOnly); }
private INZazuWpfLayoutStrategy SafeResolve(IResolveLayout resolveLayout, string name) { if (resolveLayout == null) { return(this); } var layout = resolveLayout.Resolve(name); return(layout ?? this); }
public override void DoLayout( ContentControl contentControl, IEnumerable <INZazuWpfField> fields, IResolveLayout resolveLayout = null) { if (contentControl == null) { throw new ArgumentNullException(nameof(contentControl)); } if (fields == null) { throw new ArgumentNullException(nameof(fields)); } var stackPanel = new StackPanel { Margin = new Thickness(5), Orientation = Orientation.Horizontal, VerticalAlignment = VerticalAlignment.Top, HorizontalAlignment = HorizontalAlignment.Left }; foreach (var field in fields) { var labelElement = field.LabelControl; var valueElement = field.ValueControl; if (labelElement == null && valueElement == null) { continue; } if (labelElement != null) { StyleLabel(labelElement); stackPanel.Children.Add(labelElement); } if (valueElement != null) { StyleValue(valueElement); stackPanel.Children.Add(valueElement); SetErrorTemplate(valueElement); ProcessGroupField(resolveLayout, valueElement, field); } } contentControl.Content = stackPanel; }
protected void ProcessGroupField( IResolveLayout resolveLayout, Control control, INZazuWpfField field) { var contentControl = control as ContentControl; if (!(field is INZazuWpfFieldContainer groupField) || contentControl == null) { return; } var layout = SafeResolve(resolveLayout, groupField.Layout); layout.DoLayout(contentControl, groupField.Fields, resolveLayout); }
public override void DoLayout(ContentControl contentControl, IEnumerable <INZazuWpfField> fields, IResolveLayout resolveLayout = null) { if (contentControl == null) { throw new ArgumentNullException(nameof(contentControl)); } if (fields == null) { throw new ArgumentNullException(nameof(fields)); } var grid = new Grid { Margin = new Thickness(5) }; grid.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto }); grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }); var row = 0; foreach (var field in fields) { var labelElement = field.LabelControl; var valueElement = field.ValueControl; if (labelElement == null && valueElement == null) { continue; } grid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto }); if (labelElement != null) { StyleLabel(labelElement); Grid.SetColumn(labelElement, 0); Grid.SetRow(labelElement, row); grid.Children.Add(labelElement); } if (valueElement != null) { StyleValue(valueElement); Grid.SetColumn(valueElement, 1); Grid.SetRow(valueElement, row); grid.Children.Add(valueElement); SetErrorTemplate(valueElement); ProcessGroupField(resolveLayout, valueElement, field); } row++; } contentControl.Content = grid; }
public abstract void DoLayout( ContentControl contentControl, IEnumerable <INZazuWpfField> fields, IResolveLayout resolveLayout = null);