private FrameworkElement GenerateDoubleUpDown(PropertyInfo property, Binding binding) { #if !SILVERLIGHT DoubleUpDown calculatorUpDown = new DoubleUpDown() { Margin = new Thickness(0, 3, 18, 3) }; calculatorUpDown.IsReadOnly = !(bindables[property.Name].Direction == BindingDirection.TwoWay); // Binding this.bindings.Add(property.Name, calculatorUpDown.SetBinding(DoubleUpDown.ValueProperty, binding)); #else Border calculatorUpDown = new Border() { Opacity = 1.0, Background = new SolidColorBrush(Colors.White), Margin = new Thickness(0, 3, 18, 3) }; NumericUpDown n = new NumericUpDown() { }; calculatorUpDown.Child = n; n.IsEnabled = (bindables[property.Name].Direction == BindingDirection.TwoWay); // Binding this.bindings.Add(property.Name, n.SetBinding(NumericUpDown.ValueProperty, binding)); #endif return(calculatorUpDown); }
private static FrameworkElement ExtractDouble(DisplayOption option) { var ctrl = new DoubleUpDown { FormatString = "F2", Margin = new Thickness(3), HorizontalAlignment = HorizontalAlignment.Left, MinWidth = 50 }; ctrl.SetBinding(DoubleUpDown.ValueProperty, new Binding(option.PropertyName)); double newVal; if (option.Minimum != null) { newVal = Convert.ToDouble(option.Minimum); ctrl.Minimum = newVal; } if (option.Maximum != null) { newVal = Convert.ToDouble(option.Maximum); ctrl.Maximum = newVal; } return(ctrl); }
/// <summary> /// Generates the numeric double row. /// </summary> /// <param name="gridContainer">The grid container.</param> /// <param name="item">The item.</param> /// <param name="row">The row.</param> private void GenerateNumericDoubleRow(Grid gridContainer, DnwSetting item, int row) { try { GenerateDescriptions(gridContainer, item, row); DoubleUpDown dud = new DoubleUpDown(); if (item.Mask.XDwIsNullOrTrimEmpty()) { dud.FormatString = "F6"; } else { dud.FormatString = item.Mask; } dud.Padding = new Thickness(2); dud.Margin = new Thickness(5); Binding vBinding = new Binding(DnwSetting.FLD_Value); vBinding.Source = item; dud.SetBinding(DoubleUpDown.ValueProperty, vBinding); gridContainer.Children.Add(dud); Grid.SetRow(dud, row); Grid.SetColumn(dud, 2); } catch (Exception ex) { EventLogger.SendMsg(ex); throw; } }
public static DoubleUpDown GetDoubleEditor(Binding valuePropertyBinding, double minValue = Double.MinValue, double maxValue = Double.MaxValue, bool isReadOnly = false) { var control = new DoubleUpDown(); SetNumericProperties(control, minValue, maxValue, isReadOnly); control.SetBinding(DoubleUpDown.ValueProperty, valuePropertyBinding); return(control); }
public NumberSpinner() { spinner = new DoubleUpDown() { Margin = new Thickness(2), VerticalAlignment = VerticalAlignment.Center, Value = 0 }; Content = spinner; //150x50 should be fine TileGrid.SetColumnSpan(this, 3); TileGrid.SetRowSpan(this, 1); //bind editor properties spinner.SetBinding(DoubleUpDown.MinimumProperty, this, "Minimum"); spinner.SetBinding(DoubleUpDown.MaximumProperty, this, "Maximum"); spinner.SetBinding(DoubleUpDown.IncrementProperty, this, "Interval"); SourceChanged += SourcedSpinner_SourceChanged; }
public Visual GetControl(Application application) { if (control == null) { control = new DoubleUpDown { Margin = new System.Windows.Thickness(0, 0, 0, 6) }; control.SetBinding(DoubleUpDown.ValueProperty, new Binding("Value") { Source = this }); } return(control); }
internal void SetData <T>(NumericUpDownData <T> numericUpDownControl) where T : struct, IFormattable, IComparable <T> { Control control; Binding binding = new Binding("Value"); binding.Source = numericUpDownControl; if (typeof(T) == typeof(int)) { var numeric = new IntegerUpDown(); numeric.Minimum = Convert.ToInt32(numericUpDownControl._min); numeric.Maximum = Convert.ToInt32(numericUpDownControl._max); numeric.UpdateValueOnEnterKey = true; numeric.FormatString = numericUpDownControl.FormatString; numeric.SetBinding(IntegerUpDown.ValueProperty, binding); control = numeric; } else if (typeof(T) == typeof(decimal)) { var numeric = new DecimalUpDown(); numeric.Minimum = Convert.ToDecimal(numericUpDownControl._min); numeric.Maximum = Convert.ToDecimal(numericUpDownControl._max); numeric.Increment = (numeric.Maximum - numeric.Minimum) / 100; numeric.UpdateValueOnEnterKey = true; numeric.FormatString = numericUpDownControl.FormatString; numeric.SetBinding(DecimalUpDown.ValueProperty, binding); control = numeric; } else if (typeof(T) == typeof(double)) { var numeric = new DoubleUpDown(); numeric.Minimum = Convert.ToDouble(numericUpDownControl._min); numeric.Maximum = Convert.ToDouble(numericUpDownControl._max); numeric.UpdateValueOnEnterKey = true; numeric.SetBinding(DoubleUpDown.ValueProperty, binding); numeric.FormatString = numericUpDownControl.FormatString; control = numeric; } else { throw new Exception($"Inavlid type, Expected int,double or decimal received {typeof(T)}"); } //control.Width = 200; //control.Height = 24; control.Name = "Numeric"; control.Background = Brushes.LightGoldenrodYellow; control.KeyDown += Control_KeyDown; this.PlaceHolder.Children.Add(control); }
protected override FrameworkElement GenerateEditingElement(DataGridCell cell, object dataItem) { var numericEditor = new DoubleUpDown(); numericEditor.Minimum = Minimum; numericEditor.Maximum = Maximum; numericEditor.Increment = Increment; numericEditor.FormatString = FormatString; var sourceBinding = this.Binding as System.Windows.Data.Binding; var binding = new System.Windows.Data.Binding(); binding.Path = sourceBinding.Path; binding.Converter = new TargetTypeConverter(); numericEditor.SetBinding(DoubleUpDown.ValueProperty, binding); return numericEditor; }
public override Control ProvideControl(PropertyInfo propertyInfo, object viewModel) { Binding binding = propertyInfo.GetBinding(); var editableAttribute = propertyInfo.GetAttribute <EditableAttribute>(); Control control = new DoubleUpDown(); control.SetBinding(DoubleUpDown.ValueProperty, binding); control.IsEnabled = propertyInfo.IsControlEnabled(); return(control); }
public override Control ProvideControl(PropertyInfo propertyInfo, object viewModel) { Binding binding = propertyInfo.GetBinding(); var editableAttribute = propertyInfo.GetAttribute <EditableAttribute>(); Control control = new DoubleUpDown(); control.SetBinding(DoubleUpDown.ValueProperty, binding); control.IsEnabled = editableAttribute == null || editableAttribute.AllowEdit || binding.Mode == BindingMode.TwoWay; return(control); }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (value == null) { return(null); } var valueBinding = new Binding("Value") { UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged }; FrameworkElement editor; if (value is IntParam) { editor = new IntegerUpDown { Background = Brushes.Transparent, Foreground = Brushes.Snow, BorderThickness = new Thickness(0), BorderBrush = Brushes.Transparent, Minimum = ((IntParam)value).MinValue, Maximum = ((IntParam)value).MaxValue, }; editor.SetBinding(IntegerUpDown.ValueProperty, valueBinding); return(editor); } if (value is DoubleParam) { editor = new DoubleUpDown { Background = Brushes.Transparent, Foreground = Brushes.Snow, Minimum = ((DoubleParam)value).MinValue, Maximum = ((DoubleParam)value).MaxValue, }; editor.SetBinding(DoubleUpDown.ValueProperty, valueBinding); return(editor); } if (value is StringParam && ((StringParam)value).AllowedValues.Count == 0) { editor = new TextBox { Background = Brushes.Transparent, Foreground = Brushes.Snow, HorizontalContentAlignment = HorizontalAlignment.Right }; editor.SetBinding(TextBox.TextProperty, valueBinding); return(editor); } if (value is StringParam && ((StringParam)value).AllowedValues.Count > 0) { editor = new ComboBox { BorderThickness = new Thickness(0), BorderBrush = Brushes.Transparent, ItemsSource = ((StringParam)value).AllowedValues, HorizontalContentAlignment = HorizontalAlignment.Right }; editor.SetBinding(Selector.SelectedValueProperty, valueBinding); return(editor); } if (value is ColorParam) { editor = new ColorPicker { Background = Brushes.Transparent, Foreground = Brushes.Snow, BorderThickness = new Thickness(1), BorderBrush = Brushes.Transparent, HorizontalAlignment = HorizontalAlignment.Left, Margin = new Thickness(0) }; var binding = new Binding("Value") { UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged }; editor.SetBinding(ColorPicker.SelectedColorProperty, binding); return(editor); } if (value is SeriesParam) { editor = new Grid { Background = Brushes.Transparent }; ((Grid)editor).RowDefinitions.Add(new RowDefinition()); ((Grid)editor).RowDefinitions.Add(new RowDefinition()); ((Grid)editor).ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto }); ((Grid)editor).ColumnDefinitions.Add(new ColumnDefinition()); // Color var colorEditor = new ColorPicker { Background = Brushes.Transparent, BorderThickness = new Thickness(1), BorderBrush = Brushes.Transparent, HorizontalAlignment = HorizontalAlignment.Left, Margin = new Thickness(0, 0, 0, 3) }; var colorEditorBinding = new Binding("Color") { UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged }; colorEditor.SetBinding(ColorPicker.SelectedColorProperty, colorEditorBinding); // Thickness var thicknessEditor = new IntegerUpDown { Background = Brushes.Transparent, Foreground = Brushes.Snow, BorderThickness = new Thickness(0), BorderBrush = Brushes.Transparent, Minimum = 1, Maximum = 10 }; var thicknessEditorBinding = new Binding("Thickness") { UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged }; thicknessEditor.SetBinding(IntegerUpDown.ValueProperty, thicknessEditorBinding); Grid.SetRow(colorEditor, 0); Grid.SetRow(thicknessEditor, 1); Grid.SetColumn(colorEditor, 1); Grid.SetColumn(thicknessEditor, 1); var text1 = new TextBlock { Text = "Color: ", HorizontalAlignment = HorizontalAlignment.Right, Margin = new Thickness(0, 0, 3, 0) }; var text2 = new TextBlock { Text = "Thickness: ", HorizontalAlignment = HorizontalAlignment.Right, Margin = new Thickness(0, 0, 3, 0) }; Grid.SetRow(text1, 0); Grid.SetRow(text2, 1); Grid.SetColumn(text1, 0); Grid.SetColumn(text2, 0); ((Grid)editor).Children.Add(colorEditor); ((Grid)editor).Children.Add(thicknessEditor); ((Grid)editor).Children.Add(text1); ((Grid)editor).Children.Add(text2); return(editor); } return(null); }
public static FrameworkElement GetBsonValueEditor(string bindingPath, BsonValue bindingValue, object bindingSource, bool readOnly) { var binding = new Binding() { Path = new PropertyPath(bindingPath), Source = bindingSource, Mode = BindingMode.TwoWay, Converter = new BsonValueToNetValueConverter(), UpdateSourceTrigger = UpdateSourceTrigger.Explicit }; if (bindingValue.IsArray) { var button = new Button() { Content = "Array" }; button.Click += (s, a) => { var arrayValue = bindingValue as BsonArray; var window = new Windows.ArrayViewer(arrayValue, readOnly) { Owner = Application.Current.MainWindow }; if (window.ShowDialog() == true) { arrayValue.Clear(); arrayValue.AddRange(window.EditedItems); } }; return(button); } else if (bindingValue.IsBoolean) { var check = new CheckBox() { IsEnabled = !readOnly }; check.SetBinding(ToggleButton.IsCheckedProperty, binding); return(check); } else if (bindingValue.IsDateTime) { var datePicker = new DateTimePicker() { TextAlignment = TextAlignment.Left, IsReadOnly = readOnly }; datePicker.SetBinding(DateTimePicker.ValueProperty, binding); return(datePicker); } else if (bindingValue.IsDocument) { var button = new Button() { Content = "Document" }; button.Click += (s, a) => { var window = new Windows.DocumentViewer(bindingValue as BsonDocument, readOnly) { Owner = Application.Current.MainWindow }; window.ShowDialog(); }; return(button); } else if (bindingValue.IsDouble) { var numberEditor = new DoubleUpDown() { TextAlignment = TextAlignment.Left, IsReadOnly = readOnly }; numberEditor.SetBinding(DoubleUpDown.ValueProperty, binding); return(numberEditor); } else if (bindingValue.IsInt32) { var numberEditor = new IntegerUpDown() { TextAlignment = TextAlignment.Left, IsReadOnly = readOnly }; numberEditor.SetBinding(IntegerUpDown.ValueProperty, binding); return(numberEditor); } else if (bindingValue.IsInt64) { var numberEditor = new LongUpDown() { TextAlignment = TextAlignment.Left, IsReadOnly = readOnly }; numberEditor.SetBinding(LongUpDown.ValueProperty, binding); return(numberEditor); } else if (bindingValue.IsString) { var stringEditor = new TextBox() { IsReadOnly = readOnly, AcceptsReturn = true }; stringEditor.SetBinding(TextBox.TextProperty, binding); return(stringEditor); } else if (bindingValue.IsBinary) { var text = new TextBlock() { Text = "[Binary Data]" }; return(text); } else if (bindingValue.IsObjectId) { var text = new TextBlock() { Text = bindingValue.AsString, IsEnabled = false }; return(text); } else { var stringEditor = new TextBox(); stringEditor.SetBinding(TextBox.TextProperty, binding); return(stringEditor); } }
/// <summary> /// Populates the settings panel with the settings of a given plugin. /// </summary> /// <param name="plugin">The plugin whose settings to display</param> private void PopulateSettings(Plugin plugin) { SettingsGrid.RowDefinitions.Clear(); SettingsGrid.Children.Clear(); for (int i = 0; i < plugin.Settings.Count; i++) { Setting s = plugin.Settings[i]; // add row SettingsGrid.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto }); // create label TextBlock tb = new TextBlock() { Text = plugin.T(s.ID), Margin = new Thickness(5, 5, 10, 5), VerticalAlignment = VerticalAlignment.Center }; tb.SetBinding(TextBlock.VisibilityProperty, new Binding("IsVisible") { Source = s, Mode = BindingMode.OneWay, Converter = new BooleanToVisibilityConverter() }); Grid.SetRow(tb, i); Grid.SetColumn(tb, 0); SettingsGrid.Children.Add(tb); FrameworkElement control = null; // create control if (s.Type == typeof(Boolean)) { // checkbox control = new CheckBox() { Height = 15 }; control.SetBinding(CheckBox.IsCheckedProperty, new Binding("Value") { Source = s, Mode = BindingMode.TwoWay }); } else if (s.Type == typeof(Color)) { // color selector control = new ColorPicker() { ShowAvailableColors = false, ShowStandardColors = true, Width = 50, }; if (s.PossibleValues != null) { ColorConverter converter = new ColorConverter(); ((ColorPicker)control).AvailableColors.Clear(); foreach (Color c in s.PossibleValues) { System.Windows.Media.Color color = (System.Windows.Media.Color)converter.Convert(c, null, null, null); ((ColorPicker)control).AvailableColors.Add(new ColorItem(color, c.Name)); } } control.SetBinding(ColorPicker.SelectedColorProperty, new Binding("Value") { Source = s, Mode = BindingMode.TwoWay, Converter = new ColorConverter() }); } else if (s.PossibleValues != null) { // dropdown control = new ComboBox(); foreach (Object val in s.PossibleValues) { try { String content = val.ToString(); if (s.Type == typeof(String)) content = plugin.T(val.ToString()); ((ComboBox)control).Items.Add(new ComboBoxItem { Content = content, Name = val.ToString() }); } catch (Exception exc) { U.L(LogLevel.Warning, "PLUGIN", "Could not add combobox item in plugin settings: " + exc.Message); } } ((ComboBox)control).SelectedValuePath = "Name"; control.SetBinding(ComboBox.SelectedValueProperty, new Binding("Value") { Source = s, Mode = BindingMode.TwoWay }); } else if (s.Type == typeof(String)) { // text input control = new TextBox() { MaxWidth = 400, MinWidth = 250 }; control.SetBinding(TextBox.TextProperty, new Binding("Value") { Source = s, Mode = BindingMode.TwoWay }); } else if (s.Type == typeof(Int32)) { if (s.Maximum != null) { // slider control = new Slider() { Maximum = (Int32)s.Maximum, AutoToolTipPlacement = AutoToolTipPlacement.TopLeft, Width = 200, }; if (s.Minimum != null) ((Slider)control).Minimum = (Int32)s.Minimum; control.SetBinding(Slider.ValueProperty, new Binding("Value") { Source = s, Mode = BindingMode.TwoWay }); } else { // spinner control = new IntegerUpDown(); control.SetBinding(IntegerUpDown.ValueProperty, new Binding("Value") { Source = s, Mode = BindingMode.TwoWay }); } } else if (s.Type == typeof(Double)) { if (s.Maximum != null) { // slider control = new Slider() { Maximum = (Double)s.Maximum, AutoToolTipPlacement = AutoToolTipPlacement.TopLeft, Width = 200, }; if (s.Minimum != null) ((Slider)control).Minimum = (Double)s.Minimum; control.SetBinding(Slider.ValueProperty, new Binding("Value") { Source = s, Mode = BindingMode.TwoWay }); } else { // spinner control = new DoubleUpDown(); control.SetBinding(DoubleUpDown.ValueProperty, new Binding("Value") { Source = s, Mode = BindingMode.TwoWay }); } } if (control != null) { control.Margin = new Thickness(0, 5, 0, 5); control.VerticalAlignment = VerticalAlignment.Center; control.HorizontalAlignment = HorizontalAlignment.Left; control.SetBinding(FrameworkElement.VisibilityProperty, new Binding("IsVisible") { Source = s, Mode = BindingMode.OneWay, Converter = new BooleanToVisibilityConverter() }); Grid.SetRow(control, i); Grid.SetColumn(control, 1); SettingsGrid.Children.Add(control); } } }
/// <summary> /// Populates the settings panel with the settings of a given plugin. /// </summary> /// <param name="plugin">The plugin whose settings to display</param> private void PopulateSettings(Plugin plugin) { SettingsGrid.RowDefinitions.Clear(); SettingsGrid.Children.Clear(); for (int i = 0; i < plugin.Settings.Count; i++) { Setting s = plugin.Settings[i]; // add row SettingsGrid.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto }); // create label TextBlock tb = new TextBlock() { Text = plugin.T(s.ID), Margin = new Thickness(5, 5, 10, 5), VerticalAlignment = VerticalAlignment.Center }; tb.SetBinding(TextBlock.VisibilityProperty, new Binding("IsVisible") { Source = s, Mode = BindingMode.OneWay, Converter = new BooleanToVisibilityConverter() }); Grid.SetRow(tb, i); Grid.SetColumn(tb, 0); SettingsGrid.Children.Add(tb); FrameworkElement control = null; // create control if (s.Type == typeof(Boolean)) { // checkbox control = new CheckBox() { Height = 15 }; control.SetBinding(CheckBox.IsCheckedProperty, new Binding("Value") { Source = s, Mode = BindingMode.TwoWay }); } else if (s.Type == typeof(Color)) { // color selector control = new ColorPicker() { ShowAvailableColors = false, ShowStandardColors = true, Width = 50, }; if (s.PossibleValues != null) { ColorConverter converter = new ColorConverter(); ((ColorPicker)control).AvailableColors.Clear(); foreach (Color c in s.PossibleValues) { System.Windows.Media.Color color = (System.Windows.Media.Color)converter.Convert(c, null, null, null); ((ColorPicker)control).AvailableColors.Add(new ColorItem(color, c.Name)); } } control.SetBinding(ColorPicker.SelectedColorProperty, new Binding("Value") { Source = s, Mode = BindingMode.TwoWay, Converter = new ColorConverter() }); } else if (s.PossibleValues != null) { // dropdown control = new ComboBox(); foreach (Object val in s.PossibleValues) { try { String content = val.ToString(); if (s.Type == typeof(String)) { content = plugin.T(val.ToString()); } ((ComboBox)control).Items.Add(new ComboBoxItem { Content = content, Name = val.ToString() }); } catch (Exception exc) { U.L(LogLevel.Warning, "PLUGIN", "Could not add combobox item in plugin settings: " + exc.Message); } } ((ComboBox)control).SelectedValuePath = "Name"; control.SetBinding(ComboBox.SelectedValueProperty, new Binding("Value") { Source = s, Mode = BindingMode.TwoWay }); } else if (s.Type == typeof(String)) { // text input control = new TextBox() { MaxWidth = 400, MinWidth = 250 }; control.SetBinding(TextBox.TextProperty, new Binding("Value") { Source = s, Mode = BindingMode.TwoWay }); } else if (s.Type == typeof(Int32)) { if (s.Maximum != null) { // slider control = new Slider() { Maximum = (Int32)s.Maximum, AutoToolTipPlacement = AutoToolTipPlacement.TopLeft, Width = 200, }; if (s.Minimum != null) { ((Slider)control).Minimum = (Int32)s.Minimum; } control.SetBinding(Slider.ValueProperty, new Binding("Value") { Source = s, Mode = BindingMode.TwoWay }); } else { // spinner control = new IntegerUpDown(); control.SetBinding(IntegerUpDown.ValueProperty, new Binding("Value") { Source = s, Mode = BindingMode.TwoWay }); } } else if (s.Type == typeof(Double)) { if (s.Maximum != null) { // slider control = new Slider() { Maximum = (Double)s.Maximum, AutoToolTipPlacement = AutoToolTipPlacement.TopLeft, Width = 200, }; if (s.Minimum != null) { ((Slider)control).Minimum = (Double)s.Minimum; } control.SetBinding(Slider.ValueProperty, new Binding("Value") { Source = s, Mode = BindingMode.TwoWay }); } else { // spinner control = new DoubleUpDown(); control.SetBinding(DoubleUpDown.ValueProperty, new Binding("Value") { Source = s, Mode = BindingMode.TwoWay }); } } if (control != null) { control.Margin = new Thickness(0, 5, 0, 5); control.VerticalAlignment = VerticalAlignment.Center; control.HorizontalAlignment = HorizontalAlignment.Left; control.SetBinding(FrameworkElement.VisibilityProperty, new Binding("IsVisible") { Source = s, Mode = BindingMode.OneWay, Converter = new BooleanToVisibilityConverter() }); Grid.SetRow(control, i); Grid.SetColumn(control, 1); SettingsGrid.Children.Add(control); } } }
public UserControl_DoubleData(string dataName, double dataValue) : base(dataName) { var grid_main = Content as Grid; if (grid_main != null) { var control_dataValue = new DoubleUpDown(); Binding binding_control_dataValue = new Binding("DataValue") { Source = this, Mode = BindingMode.TwoWay }; control_dataValue.SetBinding(DoubleUpDown.ValueProperty, binding_control_dataValue); grid_main.SetRowColumn(control_dataValue, 0, 1); } DataValue = dataValue; }
// TODO: Infer Null value type to handle public static FrameworkElement GetBsonValueEditor( OpenEditorMode openMode, string bindingPath, BsonValue bindingValue, object bindingSource, bool readOnly, string keyName) { var binding = new Binding { Path = new PropertyPath(bindingPath), Source = bindingSource, Mode = BindingMode.TwoWay, Converter = new BsonValueToNetValueConverter(), UpdateSourceTrigger = UpdateSourceTrigger.Explicit }; if (bindingValue.IsArray) { var arrayValue = bindingValue as BsonArray; if (openMode == OpenEditorMode.Window) { var button = new Button { Content = $"[Array] {arrayValue?.Count} {keyName}", Style = StyleKit.MaterialDesignEntryButtonStyle }; button.Click += (s, a) => { arrayValue = bindingValue as BsonArray; var windowController = new WindowController { Title = "Array Editor" }; var control = new ArrayEntryControl(arrayValue, readOnly, windowController); var window = new DialogWindow(control, windowController) { Owner = Application.Current.MainWindow, Height = 600 }; if (window.ShowDialog() == true) { arrayValue?.Clear(); arrayValue?.AddRange(control.EditedItems); button.Content = $"[Array] {arrayValue?.Count} {keyName}"; } }; return(button); } var contentView = new ContentExpander { LoadButton = { Content = $"[Array] {arrayValue?.Count} {keyName}" } }; contentView.LoadButton.Click += (s, a) => { if (contentView.ContentLoaded) { return; } arrayValue = bindingValue as BsonArray; var control = new ArrayEntryControl(arrayValue, readOnly); control.CloseRequested += (sender, args) => { contentView.Content = null; }; contentView.Content = control; }; return(contentView); } if (bindingValue.IsDocument) { var expandLabel = "[Document]"; if (openMode == OpenEditorMode.Window) { var button = new Button { Content = expandLabel, Style = StyleKit.MaterialDesignEntryButtonStyle }; button.Click += (s, a) => { var windowController = new WindowController { Title = "Document Editor" }; var bsonDocument = bindingValue as BsonDocument; var control = new DocumentEntryControl(bsonDocument, readOnly, windowController); var window = new DialogWindow(control, windowController) { Owner = Application.Current.MainWindow, Height = 600 }; window.ShowDialog(); }; return(button); } var contentView = new ContentExpander { LoadButton = { Content = expandLabel } }; contentView.LoadButton.Click += (s, a) => { if (contentView.ContentLoaded) { return; } var bsonDocument = bindingValue as BsonDocument; var control = new DocumentEntryControl(bsonDocument, readOnly); control.CloseRequested += (sender, args) => { contentView.Content = null; }; contentView.Content = control; }; return(contentView); } if (bindingValue.IsBoolean) { var check = new CheckBox { IsEnabled = !readOnly, VerticalAlignment = VerticalAlignment.Center, Margin = new Thickness(0, 0, 0, 0) }; check.SetBinding(ToggleButton.IsCheckedProperty, binding); return(check); } if (bindingValue.IsDateTime) { var datePicker = new DateTimePicker { TextAlignment = TextAlignment.Left, IsReadOnly = readOnly, VerticalAlignment = VerticalAlignment.Center, Margin = new Thickness(0, 0, 0, 0) }; datePicker.SetBinding(DateTimePicker.ValueProperty, binding); return(datePicker); } if (bindingValue.IsDouble) { var numberEditor = new DoubleUpDown { TextAlignment = TextAlignment.Left, IsReadOnly = readOnly, VerticalAlignment = VerticalAlignment.Center, Margin = new Thickness(0, 0, 0, 0) }; numberEditor.SetBinding(DoubleUpDown.ValueProperty, binding); return(numberEditor); } if (bindingValue.IsDecimal) { var numberEditor = new DecimalUpDown { TextAlignment = TextAlignment.Left, IsReadOnly = readOnly, VerticalAlignment = VerticalAlignment.Center, Margin = new Thickness(0, 0, 0, 0) }; numberEditor.SetBinding(DecimalUpDown.ValueProperty, binding); return(numberEditor); } if (bindingValue.IsInt32) { var numberEditor = new IntegerUpDown { TextAlignment = TextAlignment.Left, IsReadOnly = readOnly, VerticalAlignment = VerticalAlignment.Center, Margin = new Thickness(0, 0, 0, 0) }; numberEditor.SetBinding(IntegerUpDown.ValueProperty, binding); return(numberEditor); } if (bindingValue.IsInt64) { var numberEditor = new LongUpDown { TextAlignment = TextAlignment.Left, IsReadOnly = readOnly, VerticalAlignment = VerticalAlignment.Center, Margin = new Thickness(0, 0, 0, 0) }; numberEditor.SetBinding(LongUpDown.ValueProperty, binding); return(numberEditor); } if (bindingValue.IsString) { var stringEditor = new TextBox { IsReadOnly = readOnly, AcceptsReturn = true, VerticalAlignment = VerticalAlignment.Center, MaxHeight = 200, MaxLength = 1024, VerticalScrollBarVisibility = ScrollBarVisibility.Auto, }; stringEditor.SetBinding(TextBox.TextProperty, binding); return(stringEditor); } if (bindingValue.IsBinary) { var text = new TextBlock { Text = "[Binary Data]", VerticalAlignment = VerticalAlignment.Center, }; return(text); } if (bindingValue.IsObjectId) { var text = new TextBox { Text = bindingValue.AsString, IsReadOnly = true, VerticalAlignment = VerticalAlignment.Center, }; return(text); } var defaultEditor = new TextBox { VerticalAlignment = VerticalAlignment.Center, MaxHeight = 200, MaxLength = 1024, VerticalScrollBarVisibility = ScrollBarVisibility.Auto, }; defaultEditor.SetBinding(TextBox.TextProperty, binding); return(defaultEditor); }
private FrameworkElement OnGeneratingControl(Controllable control, ControlItem item) { FrameworkElement result = null; GeneratingControl?.Invoke(this, control, item, ref result); if (result != null) { return(result); } if (item.Type == ControlItem.PropType.Enum) { var cbox = new ComboBox { ItemsSource = item.Cookie as string[] }; cbox.SetBinding(ComboBox.SelectedItemProperty, CreateControlItemBinding(control, item)); return(cbox); } if (item.ValType == typeof(string)) { if (item.Type == ControlItem.PropType.LongText) { var btn = new Button { Content = "查看" }; btn.Click += (o, e) => { control.DoGetMember(item.Id, out object txt); new TextDialog(txt as string, $"{control.ToString()} --- {item.Name}").Show(); e.Handled = true; }; return(btn); } { var tbox = new TextBox { VerticalAlignment = VerticalAlignment.Center }; tbox.SetBinding(TextBox.TextProperty, CreateControlItemBinding(control, item)); tbox.IsReadOnly = !item.Access.HasFlag(ControlItem.PropAccess.Write); return(tbox); } } if (item.ValType == typeof(Vector2)) { var limit = (Vector2)item.Cookie; var slider = new RangeSlider { AutoToolTipPlacement = AutoToolTipPlacement.TopLeft, AutoToolTipPrecision = 3, Minimum = limit.X, Maximum = limit.Y }; slider.SetBinding(RangeSlider.LowerValueProperty, CreateControlItemBinding(control, item, new TwoWayValueConvertor( o => ((Vector2)o).X, o => new Vector2(Convert.ToSingle(o), (float)slider.HigherValue)) )); slider.SetBinding(RangeSlider.HigherValueProperty, CreateControlItemBinding(control, item, new TwoWayValueConvertor( o => ((Vector2)o).Y, o => new Vector2((float)slider.LowerValue, Convert.ToSingle(o))) )); return(slider); } if (item.ValType == typeof(Color)) { var clrPicker = new ColorPicker() { ColorMode = ColorMode.ColorCanvas }; clrPicker.SetBinding(ColorPicker.SelectedColorProperty, CreateControlItemBinding(control, item)); return(clrPicker); } if (item.ValType == typeof(float)) { if (item.Cookie == null) { var spiner = new DoubleUpDown { FormatString = "F2", Increment = 0.1 }; spiner.SetBinding(DoubleUpDown.ValueProperty, CreateControlItemBinding(control, item, ConvertorForceSingle)); return(spiner); } else { var limit = (Vector2)item.Cookie; var slider = new Slider { AutoToolTipPlacement = AutoToolTipPlacement.TopLeft, AutoToolTipPrecision = 3, Minimum = limit.X, Maximum = limit.Y }; slider.SetBinding(Slider.ValueProperty, CreateControlItemBinding(control, item, ConvertorForceSingle)); return(slider); } } if (item.ValType == typeof(ushort)) { if (item.Cookie == null) { var spiner = new IntegerUpDown { Increment = 1 }; spiner.SetBinding(IntegerUpDown.ValueProperty, CreateControlItemBinding(control, item, ConvertorForceUShort)); return(spiner); } else { dynamic limit = item.Cookie; var slider = new Slider { AutoToolTipPlacement = AutoToolTipPlacement.TopLeft, Minimum = limit.Item1, Maximum = limit.Item2 }; slider.SetBinding(Slider.ValueProperty, CreateControlItemBinding(control, item, ConvertorForceUShort)); return(slider); } } if (item.ValType == typeof(int)) { if (item.Cookie == null) { var spiner = new IntegerUpDown { Increment = 1 }; spiner.SetBinding(IntegerUpDown.ValueProperty, CreateControlItemBinding(control, item)); return(spiner); } else { dynamic limit = item.Cookie; var slider = new Slider { AutoToolTipPlacement = AutoToolTipPlacement.TopLeft, Minimum = limit.Item1, Maximum = limit.Item2 }; slider.SetBinding(Slider.ValueProperty, CreateControlItemBinding(control, item, ConvertorForceInt)); return(slider); } } if (item.ValType == typeof(bool)) { var ckBox = new CheckBox { VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center }; ckBox.SetBinding(CheckBox.IsCheckedProperty, CreateControlItemBinding(control, item)); return(ckBox); } { var tblock = new TextBlock { VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center }; tblock.SetBinding(TextBlock.TextProperty, CreateControlItemBinding(control, item)); return(tblock); } }