private void RenderToggleBox(ActionInputModel item, bool isMultiLine = false) { var control = new Toggle.Toggle(); //绑定数据 BindingOperations.SetBinding(control, Toggle.Toggle.IsCheckedProperty, new Binding() { Source = DataContext, Path = new PropertyPath(item.BindingName), Mode = BindingMode.TwoWay, }); if (!isMultiLine) { //单行 if (!item.IsStretch && LineInputGroups.Count > 1) { control.VerticalAlignment = VerticalAlignment.Center; control.Margin = new Thickness(0, 0, 10, 0); if (!string.IsNullOrEmpty(item.Title)) { LineContainer.Children.Add(GetLabel(item)); } LineContainer.Children.Add(control); } else { var grid = GetLineGrid(); var label = GetLabel(item); Grid.SetColumn(control, 1); grid.Children.Add(label); grid.Children.Add(control); label.Loaded += (e, c) => { grid.Width = LineContainer.ActualWidth; }; LineContainer.Children.Add(grid); } } else { //多行 var grid = GetLineGrid(); var label = GetLabel(item); Grid.SetColumn(control, 1); grid.Children.Add(label); grid.Children.Add(control); MultiLineContainer.Children.Add(grid); } }
private void Render() { if (container == null) { return; } container.Children.Clear(); if (Groups == null) { return; } bool isAddLabelName = true; foreach (var input in Groups) { Control control = null; switch (input.Type) { case InputType.Text: control = new InputBox() { Placeholder = input.Placeholder }; break; case InputType.Number: control = new InputBox() { InputType = InputTypes.Number, Placeholder = input.Placeholder }; break; case InputType.Bool: control = new Toggle.Toggle(); break; case InputType.Select: control = new ComboBox() { ItemsSource = input.SelectItems, SelectedValuePath = nameof(ComBoxModel.ID), DisplayMemberPath = nameof(ComBoxModel.DisplayName), }; //绑定数据 BindingOperations.SetBinding(control, ComboBox.SelectedValueProperty, new Binding() { Source = DataSource, Path = new PropertyPath($"{input.BindingName}.{nameof(ComBoxModel.ID)}"), Mode = BindingMode.TwoWay, }); BindingOperations.SetBinding(control, ComboBox.SelectedItemProperty, new Binding() { Source = DataSource, Path = new PropertyPath(input.BindingName), Mode = BindingMode.TwoWay, }); break; case InputType.DateTime: control = new InputBox() { InputType = InputTypes.DateTime, }; break; } if (isAddLabelName) { var label = new TextBlock(); label.Style = FindResource("LabelName") as Style; label.Text = input.Title; container.Children.Add(label); } if (control != null) { if (input.Type != InputType.Select) { //binding input BindingOperations.SetBinding(control, input.BindingProperty, new Binding() { Source = DataSource, Path = new PropertyPath(input.BindingName), Mode = BindingMode.TwoWay, }); } container.Children.Add(control); } } }