public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var property = value as CustomProperty;

            if (property != null)
            {
                switch (property.PropertyType)
                {
                case CustomPropertyType.Number:
                    NumericUpDown numericUpDown = new NumericUpDown();
                    numericUpDown.Minimum     = property.RangeMin;
                    numericUpDown.Maximum     = property.RangeMax;
                    numericUpDown.DataContext = property;
                    numericUpDown.SetBinding(NumericUpDown.ValueProperty, "Value");
                    return(numericUpDown);

                case CustomPropertyType.String:
                    TextBox text = new TextBox();
                    text.DataContext = property;
                    text.SetBinding(TextBox.TextProperty, "Value");
                    return(text);

                case CustomPropertyType.Color:
                    var colorpicker = new Colorpicker();
                    colorpicker.DataContext = property;
                    colorpicker.SetBinding(Colorpicker.SelectedColorProperty, new Binding("Value")
                    {
                        Mode = BindingMode.TwoWay
                    });
                    return(colorpicker);

                case CustomPropertyType.ValueList:
                {
                    ComboBox comboBox = new ComboBox();
                    comboBox.DataContext = property;
                    comboBox.SetBinding(ComboBox.ItemsSourceProperty, "ValueList");
                    comboBox.SetBinding(ComboBox.SelectedItemProperty, "Value");
                    return(comboBox);
                }

                case CustomPropertyType.Variable:
                {
                    property.InitVaribleList();
                    ComboBox comboBox = new ComboBox();
                    comboBox.DataContext = property;
                    comboBox.SetBinding(ComboBox.ItemsSourceProperty, "ValueList");
                    comboBox.SetBinding(ComboBox.SelectedItemProperty, "Value");
                    return(comboBox);
                }

                case CustomPropertyType.View:
                {
                    property.InitViewList();
                    ComboBox comboBox = new ComboBox();
                    comboBox.DataContext = property;
                    comboBox.SetBinding(ComboBox.ItemsSourceProperty, "ValueList");
                    comboBox.SetBinding(ComboBox.SelectedItemProperty, "Value");
                    return(comboBox);
                }

                case CustomPropertyType.Icon:
                    var iconicker = new IconPicker();
                    iconicker.DataContext = property;
                    iconicker.SetBinding(IconPicker.SelectedIconProperty, new Binding("Value")
                    {
                        Mode = BindingMode.TwoWay
                    });
                    return(iconicker);

                case CustomPropertyType.Bool:
                    CheckBox checkBox = new CheckBox();
                    checkBox.DataContext = property;
                    checkBox.SetBinding(CheckBox.IsCheckedProperty, "Value");
                    return(checkBox);

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
            return(null);
        }
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var property = value as CustomProperty;

            if (property != null)
            {
                switch (property.PropertyType)
                {
                //case CustomPropertyType.Number:
                //    NumericUpDown numericUpDown = new NumericUpDown();
                //    numericUpDown.Minimum = property.RangeMin;
                //    numericUpDown.Maximum = property.RangeMax;
                //    numericUpDown.DataContext = property;
                //    numericUpDown.SetBinding(NumericUpDown.ValueProperty, "Value");
                //    return numericUpDown;
                case CustomPropertyType.Code:
                case CustomPropertyType.String:
                case CustomPropertyType.Number:
                {
                    TextBox text = new TextBox();
                    text.DataContext = property;
                    text.SetBinding(TextBox.TextProperty, "Value");
                    return(text);
                }

                case CustomPropertyType.ParamString:
                {
                    TextBox text = new TextBox();
                    text.DataContext = property;
                    text.SetBinding(TextBox.TextProperty, "Value");
                    return(text);
                }

                case CustomPropertyType.Color:
                    var colorpicker = new Colorpicker();
                    colorpicker.DataContext = property;
                    colorpicker.SetBinding(Colorpicker.SelectedColorProperty,
                                           new Binding("Value")
                    {
                        Mode = BindingMode.TwoWay
                    });
                    return(colorpicker);

                case CustomPropertyType.ValueList:
                {
                    ComboBox comboBox = new ComboBox();
                    comboBox.DataContext = property;
                    comboBox.SetBinding(ComboBox.ItemsSourceProperty, "ValueList");
                    comboBox.SetBinding(ComboBox.SelectedItemProperty, "Value");
                    return(comboBox);
                }

                case CustomPropertyType.Variable:
                {
                    property.InitVaribleList();
                    ComboBox comboBox = new ComboBox();
                    comboBox.DataContext = property;
                    comboBox.SetBinding(ComboBox.ItemsSourceProperty, "ValueList");
                    comboBox.SetBinding(ComboBox.SelectedItemProperty, "Value");
                    return(comboBox);
                }

                case CustomPropertyType.View:
                {
                    property.InitViewList();
                    ComboBox comboBox = new ComboBox();
                    comboBox.DataContext = property;
                    comboBox.SetBinding(ComboBox.ItemsSourceProperty, "ValueList");
                    comboBox.SetBinding(ComboBox.SelectedItemProperty, "Value");
                    return(comboBox);
                }

                case CustomPropertyType.Icon:
                    var iconicker = new IconPicker();
                    iconicker.DataContext = property;
                    iconicker.SetBinding(IconPicker.SelectedIconProperty,
                                         new Binding("Value")
                    {
                        Mode = BindingMode.TwoWay
                    });
                    return(iconicker);

                case CustomPropertyType.Bool:
                    CheckBox checkBox = new CheckBox();
                    checkBox.DataContext = property;
                    checkBox.SetBinding(CheckBox.IsCheckedProperty, "Value");
                    return(checkBox);

                case CustomPropertyType.File:
                {
                    TextBox text = new TextBox();
                    text.DataContext = property;
                    text.SetBinding(TextBox.TextProperty, "Value");
                    text.HorizontalAlignment      = HorizontalAlignment.Stretch;
                    text.VerticalContentAlignment = VerticalAlignment.Center;
                    text.Margin = new Thickness(0, 0, 50, 0);
                    Button button = new Button();
                    button.HorizontalAlignment = HorizontalAlignment.Right;
                    button.Content             = "...";
                    button.Click += (sender, e) =>
                    {
                        OpenFileDialog dialog = new OpenFileDialog();
                        if (dialog.ShowDialog() == true)
                        {
                            property.Value = dialog.FileName;
                        }
                    };
                    var stackpanel = new Grid {
                        HorizontalAlignment = HorizontalAlignment.Stretch
                    };
                    stackpanel.Children.Add(text);
                    stackpanel.Children.Add(button);
                    return(stackpanel);
                }

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
            return(null);
        }