/// <summary>
 /// Generates the numeric integer row.
 /// </summary>
 /// <param name="gridContainer">The grid container.</param>
 /// <param name="item">The item.</param>
 /// <param name="row">The row.</param>
 private void GenerateNumericIntegerRow(Grid gridContainer, DnwSetting item, int row)
 {
     try
     {
         GenerateDescriptions(gridContainer, item, row);
         IntegerUpDown iud = new IntegerUpDown();
         if (item.Mask.XDwIsNullOrTrimEmpty())
         {
             iud.FormatString = "N0";
         }
         else
         {
             iud.FormatString = item.Mask;
         }
         iud.Padding = new Thickness(2);
         iud.Margin  = new Thickness(5);
         Binding vBinding = new Binding(DnwSetting.FLD_Value);
         vBinding.Source = item;
         iud.SetBinding(IntegerUpDown.ValueProperty, vBinding);
         gridContainer.Children.Add(iud);
         Grid.SetRow(iud, row);
         Grid.SetColumn(iud, 2);
     }
     catch (Exception ex)
     {
         EventLogger.SendMsg(ex);
         throw;
     }
 }
        private static FrameworkElement ExtractInt(DisplayOption option)
        {
            var ctrl = new IntegerUpDown
            {
                Margin = new Thickness(3),
                HorizontalAlignment = HorizontalAlignment.Left,
                MinWidth            = 50
            };

            ctrl.SetBinding(IntegerUpDown.ValueProperty, new Binding(option.PropertyName));

            int newVal;

            if (option.Minimum != null)
            {
                newVal       = Convert.ToInt32(option.Minimum);
                ctrl.Minimum = newVal;
            }
            if (option.Maximum != null)
            {
                newVal       = Convert.ToInt32(option.Maximum);
                ctrl.Maximum = newVal;
            }
            return(ctrl);
        }
Exemple #3
0
        private void InitializeMatrixGrid()
        {
            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    int           index         = 3 * i + j;
                    IntegerUpDown integerUpDown = new IntegerUpDown()
                    {
                        Margin        = new Thickness(5),
                        Height        = 20,
                        TextAlignment = TextAlignment.Center
                    };

                    Binding binding = new Binding
                    {
                        Mode = BindingMode.TwoWay,
                        Path = new PropertyPath("Filter.MatrixFilter[" + index + "].Value")
                    };
                    integerUpDown.SetBinding(IntegerUpDown.ValueProperty, binding);
                    Grid.SetColumn(integerUpDown, i);
                    Grid.SetRow(integerUpDown, j);
                    MatrixGrid.Children.Add(integerUpDown);
                }
            }
        }
        public static IntegerUpDown GetIntegerEditor(Binding valuePropertyBinding, int minValue = Int32.MinValue, int maxValue = Int32.MaxValue, bool isReadOnly = false)
        {
            var control = new IntegerUpDown();

            SetNumericProperties(control, minValue, maxValue, isReadOnly);
            control.SetBinding(IntegerUpDown.ValueProperty, valuePropertyBinding);
            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);
        }
        private FrameworkElement GenerateIntegerUpDow(PropertyInfo property, Binding binding)
        {
#if !SILVERLIGHT
            IntegerUpDown integerUpDown = new IntegerUpDown()
            {
                Margin = new Thickness(0, 3, 18, 3)
            };
            integerUpDown.IsReadOnly = !(bindables[property.Name].Direction == BindingDirection.TwoWay);

            if (property.PropertyType == typeof(Int32) || property.PropertyType == typeof(Int32?))
            {
                integerUpDown.Maximum = Int32.MaxValue;
                integerUpDown.Minimum = Int32.MinValue;
            }
            else if (property.PropertyType == typeof(UInt32) || property.PropertyType == typeof(UInt32?))
            {
                integerUpDown.Maximum = Int32.MaxValue;
                integerUpDown.Minimum = 0;
            }

            // Binding
            this.bindings.Add(property.Name, integerUpDown.SetBinding(IntegerUpDown.ValueProperty, binding));
#else
            Border integerUpDown = new Border()
            {
                Opacity = 1.0, Background = new SolidColorBrush(Colors.White), Margin = new Thickness(0, 3, 18, 3)
            };
            NumericUpDown n = new NumericUpDown()
            {
            };
            integerUpDown.Child = n;
            n.IsEnabled         = (bindables[property.Name].Direction == BindingDirection.TwoWay);

            if (property.PropertyType == typeof(Int32) || property.PropertyType == typeof(Int32?))
            {
                n.Maximum = Int32.MaxValue;
                n.Minimum = Int32.MinValue;
            }
            else if (property.PropertyType == typeof(UInt32) || property.PropertyType == typeof(UInt32?))
            {
                n.Maximum = UInt32.MaxValue;
                n.Minimum = UInt32.MinValue;
            }


            // Binding
            this.bindings.Add(property.Name, n.SetBinding(NumericUpDown.ValueProperty, binding));
#endif
            return(integerUpDown);
        }
Exemple #7
0
        public override Control ProvideControl(PropertyInfo propertyInfo, object viewModel)
        {
            Binding binding = propertyInfo.GetBinding();

            var editableAttribute = propertyInfo.GetAttribute <EditableAttribute>();

            Control control = new IntegerUpDown();

            control.SetBinding(IntegerUpDown.ValueProperty, binding);
            control.IsEnabled = propertyInfo.IsControlEnabled();


            return(control);
        }
        private Control GetControlByType(RdlType.ReportParameterType parameter, Binding paramValueBind)
        {
            Control paramControl       = new TextBox();
            BindingExpressionBase expr = null;

            if (parameter.HasValidValues)
            {
                paramControl = new ComboBox()
                {
                    ItemsSource       = viewModel.ReportType.GetReportParameterValidValues(parameter.Name),
                    SelectedValuePath = "Value",
                    DisplayMemberPath = "Key"
                };

                expr = paramControl.SetBinding(ComboBox.SelectedValueProperty, paramValueBind);
            }
            else
            {
                switch (parameter.DataType)
                {
                case RdlType.ReportParameterType.DataTypeEnum.DateTime:
                    paramControl = new DatePicker();
                    expr         = paramControl.SetBinding(DatePicker.SelectedDateProperty, paramValueBind);
                    break;

                case RdlType.ReportParameterType.DataTypeEnum.Boolean:
                    paramControl = new CheckBox();
                    expr         = paramControl.SetBinding(CheckBox.IsCheckedProperty, paramValueBind);
                    break;

                case RdlType.ReportParameterType.DataTypeEnum.Integer:
                    paramControl = new IntegerUpDown();
                    expr         = paramControl.SetBinding(IntegerUpDown.ValueProperty, paramValueBind);
                    break;

                case RdlType.ReportParameterType.DataTypeEnum.Float:
                    paramControl = new DecimalUpDown();
                    expr         = paramControl.SetBinding(DecimalUpDown.ValueProperty, paramValueBind);
                    break;

                default:
                    expr = paramControl.SetBinding(TextBox.TextProperty, paramValueBind);
                    break;
                }
            }

            viewModel.ClearParameters += (sender, args) => expr.UpdateTarget();
            return(paramControl);
        }
Exemple #9
0
        public override Control ProvideControl(PropertyInfo propertyInfo, object viewModel)
        {
            Binding binding = propertyInfo.GetBinding();

            var editableAttribute = propertyInfo.GetAttribute <EditableAttribute>();

            Control control = new IntegerUpDown();

            control.SetBinding(IntegerUpDown.ValueProperty, binding);
            control.IsEnabled = editableAttribute == null || editableAttribute.AllowEdit ||
                                binding.Mode == BindingMode.TwoWay;


            return(control);
        }
Exemple #10
0
        /// <summary>
        /// 反射以增加Ui配置项
        /// </summary>
        private void CreateUi()
        {
            if (Container.Children.Count > 1)
            {
                Container.Children.RemoveRange(1, Container.Children.Count);
            }

            var properties = EasingFunctionBase.GetType()
                             .GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly);

            foreach (var propertyInfo in properties)
            {
                var grid = new Grid {
                    Margin = new Thickness(5, 0, 5, 0)
                };
                grid.ColumnDefinitions.Add(new ColumnDefinition {
                    MinWidth = 100, Width = GridLength.Auto
                });
                grid.ColumnDefinitions.Add(new ColumnDefinition());

                var label = new Label {
                    Content = propertyInfo.Name, HorizontalAlignment = HorizontalAlignment.Right
                };
                Grid.SetColumn(label, 0);
                grid.Children.Add(label);

                var integerUpDown = new IntegerUpDown {
                    VerticalAlignment = VerticalAlignment.Center, MinWidth = 100
                };
                var binding = new Binding(propertyInfo.Name)
                {
                    Mode = BindingMode.TwoWay,
                    UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
                };
                integerUpDown.SetBinding(IntegerUpDown.ValueProperty, binding);
                Grid.SetColumn(integerUpDown, 1);
                grid.Children.Add(integerUpDown);

                integerUpDown.ValueChanged += (sender, args) =>
                {
                    ConfigEasingFunctionChanged?.Invoke(this, EventArgs.Empty);
                };

                Container.Children.Add(grid);
            }
        }
Exemple #11
0
        public List <WDetailSingleRowViewModel> CustomizeHeader(PropertyInfo property, string display_name, bool is_editable, object source)
        {
            WDetailSingleRowViewModel integer_row = new WDetailSingleRowViewModel(display_name);

            IntegerUpDown integerupdown = new IntegerUpDown();

            integerupdown.IsEnabled = is_editable;

            Binding tbind = new Binding(property.Name);

            tbind.Source = source;
            tbind.Mode   = BindingMode.TwoWay;
            tbind.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;

            integerupdown.SetBinding(IntegerUpDown.ValueProperty, tbind);

            integer_row.PropertyControl = integerupdown;

            return(new List <WDetailSingleRowViewModel>()
            {
                integer_row
            });
        }
        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);
            }
        }
	    private Control GetControlByType(RdlType.ReportParameterType parameter, Binding paramValueBind)
	    {
            Control paramControl = new TextBox();
	        BindingExpressionBase expr = null;

	        if (parameter.HasValidValues)
	        {
	            paramControl = new ComboBox()
	            {
	                ItemsSource = viewModel.ReportType.GetReportParameterValidValues(parameter.Name),
	                SelectedValuePath = "Value",
	                DisplayMemberPath = "Key"
	            };

	            expr = paramControl.SetBinding(ComboBox.SelectedValueProperty, paramValueBind);
	        }
	        else
	        {

	            switch (parameter.DataType)
	            {
	                case RdlType.ReportParameterType.DataTypeEnum.DateTime:
	                    paramControl = new DatePicker();
	                    expr = paramControl.SetBinding(DatePicker.SelectedDateProperty, paramValueBind);
	                    break;

	                case RdlType.ReportParameterType.DataTypeEnum.Boolean:
	                    paramControl = new CheckBox();
	                    expr = paramControl.SetBinding(CheckBox.IsCheckedProperty, paramValueBind);
	                    break;

	                case RdlType.ReportParameterType.DataTypeEnum.Integer:
	                    paramControl = new IntegerUpDown();
	                    expr = paramControl.SetBinding(IntegerUpDown.ValueProperty, paramValueBind);
	                    break;

	                case RdlType.ReportParameterType.DataTypeEnum.Float:
	                    paramControl = new DecimalUpDown();
	                    expr = paramControl.SetBinding(DecimalUpDown.ValueProperty, paramValueBind);
	                    break;

	                default:
	                    expr = paramControl.SetBinding(TextBox.TextProperty, paramValueBind);
	                    break;
	            }
	        }
           
	        viewModel.ClearParameters += (sender, args) => expr.UpdateTarget();
	        return paramControl;
	    }
Exemple #14
0
        /// <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);
                }
            }
        }
Exemple #15
0
        /// <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_IntData(string dataName, int dataValue)
                : base(dataName)
            {
                var grid_main = Content as Grid;
                if (grid_main != null)
                {

                    var control_dataValue = new IntegerUpDown();
                    Binding binding_control_dataValue =
                        new Binding("DataValue")
                        {
                            Source = this,
                            Mode = BindingMode.TwoWay
                        };
                    control_dataValue.SetBinding(IntegerUpDown.ValueProperty, binding_control_dataValue);

                    grid_main.SetRowColumn(control_dataValue, 0, 1);
                }

                DataValue = dataValue;
            }
        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);
        }
Exemple #18
0
        private void CreateExtenderSettings()
        {
            var props = from p in typeof(OsiExtenderSettings).GetProperties()
                        let attr = p.GetCustomAttributes(typeof(SettingsEntryAttribute), true)
                                   where attr.Length == 1
                                   select new { Property = p, Attribute = attr.First() as SettingsEntryAttribute };

            int count = ExtenderSettingsAutoGrid.RowCount + props.Count();
            int row   = ExtenderSettingsAutoGrid.RowCount + 1;

            ExtenderSettingsAutoGrid.Children.Clear();

            ExtenderSettingsAutoGrid.RowCount = count;
            ExtenderSettingsAutoGrid.Rows     = String.Join(",", Enumerable.Repeat("auto", count));
            DivinityApp.Log($"{count} = {ExtenderSettingsAutoGrid.Rows}");

            foreach (var prop in props)
            {
                row++;
                TextBlock tb = new TextBlock();
                tb.Text    = prop.Attribute.DisplayName;
                tb.ToolTip = prop.Attribute.Tooltip;
                ExtenderSettingsAutoGrid.Children.Add(tb);
                Grid.SetRow(tb, row);

                BoolToVisibilityConverter boolToVisibilityConverter = (BoolToVisibilityConverter)FindResource("BoolToVisibilityConverter");

                if (prop.Attribute.IsDebug)
                {
                    tb.SetBinding(TextBlock.VisibilityProperty, new Binding("DebugModeEnabled")
                    {
                        Source        = ViewModel,
                        Converter     = boolToVisibilityConverter,
                        FallbackValue = Visibility.Collapsed
                    });
                }

                var propType = Type.GetTypeCode(prop.Property.PropertyType);

                if (prop.Attribute.DisplayName == "Osiris Debugger Flags")
                {
                    propType = TypeCode.String;
                }

                switch (propType)
                {
                case TypeCode.Boolean:
                    CheckBox cb = new CheckBox();
                    cb.ToolTip           = prop.Attribute.Tooltip;
                    cb.VerticalAlignment = VerticalAlignment.Center;
                    //cb.HorizontalAlignment = HorizontalAlignment.Right;
                    cb.SetBinding(CheckBox.IsCheckedProperty, new Binding(prop.Property.Name)
                    {
                        Source = ViewModel.ExtenderSettings,
                        Mode   = BindingMode.TwoWay,
                        UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
                    });
                    if (prop.Attribute.IsDebug)
                    {
                        cb.SetBinding(CheckBox.VisibilityProperty, new Binding("DebugModeEnabled")
                        {
                            Source        = ViewModel,
                            Converter     = boolToVisibilityConverter,
                            FallbackValue = Visibility.Collapsed
                        });
                    }
                    ExtenderSettingsAutoGrid.Children.Add(cb);
                    Grid.SetRow(cb, row);
                    Grid.SetColumn(cb, 1);
                    break;

                case TypeCode.String:
                    UnfocusableTextBox utb = new UnfocusableTextBox();
                    utb.ToolTip           = prop.Attribute.Tooltip;
                    utb.VerticalAlignment = VerticalAlignment.Center;
                    //utb.HorizontalAlignment = HorizontalAlignment.Stretch;
                    utb.TextAlignment = TextAlignment.Left;
                    utb.SetBinding(UnfocusableTextBox.TextProperty, new Binding(prop.Property.Name)
                    {
                        Source = ViewModel.ExtenderSettings,
                        Mode   = BindingMode.TwoWay,
                        UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
                    });
                    if (prop.Attribute.IsDebug)
                    {
                        utb.SetBinding(CheckBox.VisibilityProperty, new Binding("DebugModeEnabled")
                        {
                            Source        = ViewModel,
                            Converter     = boolToVisibilityConverter,
                            FallbackValue = Visibility.Collapsed
                        });
                    }
                    ExtenderSettingsAutoGrid.Children.Add(utb);
                    Grid.SetRow(utb, row);
                    Grid.SetColumn(utb, 1);
                    break;

                case TypeCode.Int32:
                case TypeCode.Int64:
                    IntegerUpDown ud = new IntegerUpDown();
                    ud.ToolTip             = prop.Attribute.Tooltip;
                    ud.VerticalAlignment   = VerticalAlignment.Center;
                    ud.HorizontalAlignment = HorizontalAlignment.Left;
                    ud.Padding             = new Thickness(4, 2, 4, 2);
                    ud.AllowTextInput      = true;
                    ud.SetBinding(IntegerUpDown.ValueProperty, new Binding(prop.Property.Name)
                    {
                        Source = ViewModel.ExtenderSettings,
                        Mode   = BindingMode.TwoWay,
                        UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
                    });
                    if (prop.Attribute.IsDebug)
                    {
                        ud.SetBinding(VisibilityProperty, new Binding("DebugModeEnabled")
                        {
                            Source        = ViewModel,
                            Converter     = boolToVisibilityConverter,
                            FallbackValue = Visibility.Collapsed
                        });
                    }
                    ExtenderSettingsAutoGrid.Children.Add(ud);
                    Grid.SetRow(ud, row);
                    Grid.SetColumn(ud, 1);
                    break;
                }
            }
        }
        // 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);
            }
        }