public AddEditGenericUiControl AddProperty(GenericUiPropertyElement property) { if (null == Properties) { Properties = new List <GenericUiPropertyElement>(); } Properties.Add(property); return(this); }
private void AddElement(GenericUiPropertyElement element) { if (element.ElementType == UiElementBindingType.TextBox) { MainGrid.RowDefinitions.Add(new RowDefinition()); var textBox = new TextBox(); textBox.SetValue(HintAssist.HintProperty, element.Label); textBox.FontSize = 18; textBox.Style = this.FindResource("MaterialDesignFloatingHintTextBox") as Style; Binding myBinding = new Binding { Source = Model, Path = new PropertyPath(element.PropertyName), Mode = BindingMode.TwoWay, UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged, ValidatesOnDataErrors = true, }; element.ValidationRules.ForEach(x => { myBinding.ValidationRules.Add(x); }); BindingOperations.SetBinding(textBox, TextBox.TextProperty, myBinding); Grid.SetRow(textBox, MainGrid.RowDefinitions.Count - 1); MainGrid.Children.Add(textBox); } else if (element.ElementType == UiElementBindingType.ComboBox) { MainGrid.RowDefinitions.Add(new RowDefinition()); ComboBox combobox = new ComboBox(); //var grdEncoding = new ASCIIEncoding(); //var str = // String.Format(comboBoxString, element.Label, MainGrid.RowDefinitions.Count - 1, // element.ComboBoxSettings.SelectedValuePath, element.ComboBoxSettings.SelectedValue, // element.ComboBoxSettings.DisplayMemberPath); //var grdBytes = grdEncoding.GetBytes(str); //combobox = (ComboBox)XamlReader.Load(new MemoryStream(grdBytes)); Grid.SetRow(combobox, MainGrid.RowDefinitions.Count - 1); combobox.SetBinding( ItemsControl.ItemsSourceProperty, new Binding { Source = element.ComboBoxSettings.ItemsSource }); combobox.DisplayMemberPath = element.ComboBoxSettings.DisplayMemberPath; combobox.SelectedValuePath = element.ComboBoxSettings.SelectedValuePath; Binding myBinding = new Binding { Source = Model, Path = new PropertyPath(element.ComboBoxSettings.SelectedValue), }; combobox.SetBinding( Selector.SelectedValueProperty, myBinding); combobox.SetValue(HintAssist.HintProperty, element.Label); combobox.SetValue(HintAssist.IsFloatingProperty, true); MainGrid.Children.Add(combobox); } }