public void InvalidateForm() { if (partGrid != null) { partGrid.Children.Clear(); this.DiscoverObject(); Grid grid1 = new Grid(); grid1.Margin = new Thickness(5); grid1.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Auto) }); grid1.ColumnDefinitions.Add(new ColumnDefinition());// {Width = new GridLength(1, GridUnitType.Auto)}); //grid1.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Auto) }); int row = 0; var listProperties = from p in this.displays orderby(p.Value.GetOrder() ?? 0) select this.properties[p.Key]; foreach (PropertyInfo property in listProperties) { var nm = displays[property.Name].GetName(); if (string.IsNullOrEmpty(nm)) { nm = property.Name; } var tooltip = displays[property.Name].GetDescription(); var lbl = GetLabelTextBlock(nm, tooltip); // Binding Creation Binding binding = new Binding(property.Name); binding.Source = this.CurrentItem; binding.ConverterCulture = CultureInfo.CurrentCulture; binding.Mode = (bindables[property.Name].Direction == BindingDirection.TwoWay ? BindingMode.TwoWay : BindingMode.OneWay); binding.ValidatesOnDataErrors = true; binding.ValidatesOnExceptions = true; binding.NotifyOnValidationError = true; binding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged; #if !SILVERLIGHT //binding.NotifyOnTargetUpdated = true; //binding.NotifyOnSourceUpdated = true; //binding.IsAsync = true; #endif #if !SILVERLIGHT foreach (ValidationAttribute attribs in this.validations[property.Name]) { ValidationRule rule = new AttributeValidationRule(attribs, property.Name); binding.ValidationRules.Add(rule); if (!this.rules.ContainsKey(property.Name)) { this.rules.Add(property.Name, new List <ValidationRule>()); } this.rules[property.Name].Add(rule); } #endif // Control creation FrameworkElement editorControl = this.GetControlFromProperty(property, binding); if (editorControl == null) { continue; } var df = new DataField() { Content = editorControl, Label = lbl }; DataFormAutoGeneratingFieldEventArgs e = new DataFormAutoGeneratingFieldEventArgs(property.Name, property.PropertyType, df); EventHandler <DataFormAutoGeneratingFieldEventArgs> eventHandler = this.AutoGeneratingField; if (eventHandler != null) { eventHandler(this, e); } if (e.Cancel) { continue; } ToolTipService.SetToolTip(df.Content, displays[property.Name].GetDescription()); #if !SILVERLIGHT Validation.SetErrorTemplate(df.Content, ErrorTemplate); #endif //df.Content.HorizontalAlignment = Windows.HorizontalAlignment.Stretch; // Add to view RowDefinition newRow = new RowDefinition() { Height = new GridLength(1, GridUnitType.Auto) }; grid1.RowDefinitions.Add(newRow); if (df.Content.Height.CompareTo(Double.NaN) != 0) { newRow.Height = new GridLength(df.Content.Height); } Grid.SetColumn(df.Label, 0); Grid.SetRow(df.Label, row); Grid.SetColumn(df.Content, 1); Grid.SetRow(df.Content, row); grid1.Children.Add(df.Label); grid1.Children.Add(df.Content); this.controls.Add(property.Name, df.Content); row++; } partGrid.Children.Add(grid1); } }