private FrameworkElement CreateFilePicker(PropertyDefinition property, int index)
        {
            var c = new FilePicker
            {
                Filter        = "Image Files (*.jpg, *.png)|*.jpg;*.png",
                UseOpenDialog = true,
            };

            c.SetBinding(FilePicker.FilePathProperty, property.CreateBinding(index));
            return(c);
        }
Example #2
0
        /// <summary>
        /// Creates the extended toolkit control.
        /// </summary>
        /// <param name="propertyDefinition">The property definition.</param>
        /// <param name="bindingPath">The binding path.</param>
        /// <returns>A FrameworkElement.</returns>
        public FrameworkElement CreateExtendedToolkitControl(PropertyDefinition propertyDefinition, string bindingPath)
        {
            var propertyType = propertyDefinition.PropertyType;

            if (propertyType.Is(typeof(DateTime)))
            {
                var c = new DateTimePicker
                {
                    VerticalAlignment   = VerticalAlignment.Center,
                    HorizontalAlignment = HorizontalAlignment.Stretch,
                    IsReadOnly          = propertyDefinition.IsReadOnly
                };
                c.SetBinding(DateTimePicker.ValueProperty, propertyDefinition.CreateBinding(bindingPath));
                return(c);
            }

            if (propertyType.Is(typeof(TimeSpan)))
            {
                var c = new TimeSpanUpDown
                {
                    VerticalAlignment   = VerticalAlignment.Center,
                    HorizontalAlignment = HorizontalAlignment.Stretch,
                    IsReadOnly          = propertyDefinition.IsReadOnly
                };
                c.SetBinding(TimeSpanUpDown.ValueProperty, propertyDefinition.CreateBinding(bindingPath));
                return(c);
            }

            if (propertyType.Is(typeof(int)) || propertyType.Is(typeof(int?)))
            {
                var c = new CalculatorUpDown
                {
                    VerticalAlignment   = VerticalAlignment.Center,
                    HorizontalAlignment = HorizontalAlignment.Stretch,
                    Minimum             = int.MinValue,
                    Maximum             = int.MaxValue,
                    IsReadOnly          = propertyDefinition.IsReadOnly
                };
                c.SetBinding(CalculatorUpDown.ValueProperty, propertyDefinition.CreateBinding(bindingPath));
                return(c);
            }

            if (propertyType.Is(typeof(uint)) || propertyType.Is(typeof(uint?)))
            {
                var c = new CalculatorUpDown
                {
                    VerticalAlignment   = VerticalAlignment.Center,
                    HorizontalAlignment = HorizontalAlignment.Stretch,
                    Minimum             = 0,
                    Maximum             = uint.MaxValue,
                    IsReadOnly          = propertyDefinition.IsReadOnly
                };
                c.SetBinding(CalculatorUpDown.ValueProperty, propertyDefinition.CreateBinding(bindingPath));
                return(c);
            }

            if (propertyType.Is(typeof(decimal)) || propertyType.Is(typeof(decimal?)))
            {
                var c = new CalculatorUpDown
                {
                    VerticalAlignment   = VerticalAlignment.Center,
                    HorizontalAlignment = HorizontalAlignment.Stretch,
                    Minimum             = decimal.MinValue,
                    Maximum             = decimal.MaxValue,
                    IsReadOnly          = propertyDefinition.IsReadOnly
                };
                c.SetBinding(CalculatorUpDown.ValueProperty, propertyDefinition.CreateBinding(bindingPath));
                return(c);
            }

            if (propertyType.Is(typeof(float)) || propertyType.Is(typeof(float?)))
            {
                var c = new CalculatorUpDown
                {
                    VerticalAlignment   = VerticalAlignment.Center,
                    HorizontalAlignment = HorizontalAlignment.Stretch,
                    Minimum             = decimal.MinValue,
                    Maximum             = decimal.MaxValue,
                    IsReadOnly          = propertyDefinition.IsReadOnly
                };
                c.SetBinding(CalculatorUpDown.ValueProperty, propertyDefinition.CreateBinding(bindingPath));
                return(c);
            }

            if (propertyType.Is(typeof(double)) || propertyType.Is(typeof(double?)))
            {
                var c = new CalculatorUpDown
                {
                    VerticalAlignment   = VerticalAlignment.Center,
                    HorizontalAlignment = HorizontalAlignment.Stretch,
                    Minimum             = decimal.MinValue,
                    Maximum             = decimal.MaxValue,
                    IsReadOnly          = propertyDefinition.IsReadOnly
                };
                c.SetBinding(CalculatorUpDown.ValueProperty, propertyDefinition.CreateBinding(bindingPath));
                return(c);
            }

            if (propertyType.Is(typeof(Brush)))
            {
                var c = new ColorBox.ColorBox
                {
                    VerticalAlignment   = VerticalAlignment.Center,
                    HorizontalAlignment = HorizontalAlignment.Stretch,
                };
                c.SetBinding(ColorBox.ColorBox.BrushProperty, propertyDefinition.CreateBinding(bindingPath));
                return(c);
            }

            if (propertyType.Is(typeof(Guid)) || propertyType.Is(typeof(Guid?)))
            {
                var c = new MaskedTextBox
                {
                    VerticalAlignment   = VerticalAlignment.Center,
                    HorizontalAlignment = HorizontalAlignment.Stretch,
                    Mask       = "AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA",
                    IsReadOnly = propertyDefinition.IsReadOnly
                };
                c.SetBinding(TextBox.TextProperty, propertyDefinition.CreateBinding(bindingPath));
                return(c);
            }

            if (propertyType.Is(typeof(char)) || propertyType.Is(typeof(char?)))
            {
                var c = new MaskedTextBox
                {
                    VerticalAlignment   = VerticalAlignment.Center,
                    HorizontalAlignment = HorizontalAlignment.Stretch,
                    Mask       = "&",
                    IsReadOnly = propertyDefinition.IsReadOnly
                };
                c.SetBinding(TextBox.TextProperty, propertyDefinition.CreateBinding(bindingPath));
                return(c);
            }

            return(null);
        }
 /// <summary>
 /// Creates the check box control.
 /// </summary>
 /// <param name="property">The property.</param>
 /// <returns></returns>
 protected virtual FrameworkElement CreateCheckBoxControl(PropertyDefinition property)
 {
     var c = new CheckBox { VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = property.HorizontalAlignment };
     c.SetBinding(ToggleButton.IsCheckedProperty, property.CreateBinding());
     return c;
 }
        /// <summary>
        /// Creates the text box.
        /// </summary>
        /// <param name="d">The d.</param>
        /// <returns></returns>
        protected virtual FrameworkElement CreateTextBox(PropertyDefinition d)
        {
            var tb = new TextBox
            {
                HorizontalAlignment = HorizontalAlignment.Stretch,
                HorizontalContentAlignment = d.HorizontalAlignment,
                MaxLength = d.MaxLength,
                BorderThickness = new Thickness(0),
                Margin = new Thickness(1, 1, 0, 0)
            };
            tb.SetBinding(TextBox.TextProperty, d.CreateBinding());

            return tb;
        }
        /// <summary>
        /// Creates the combo box.
        /// </summary>
        /// <param name="d">The d.</param>
        /// <returns></returns>
        protected virtual FrameworkElement CreateComboBox(PropertyDefinition d)
        {
            var c = new ComboBox { IsEditable = d.IsEditable, Focusable = false, Margin = new Thickness(0, 0, -1, -1) };
            if (d.ItemsSource != null)
                c.ItemsSource = d.ItemsSource;
            else
            {
                if (d.ItemsSourceProperty != null) c.SetBinding(ItemsControl.ItemsSourceProperty, new Binding(d.ItemsSourceProperty));
            }

            c.SetBinding(d.IsEditable ? ComboBox.TextProperty : Selector.SelectedValueProperty, d.CreateBinding());
            return c;
        }
 protected virtual FrameworkElement CreateColorPreviewControl(PropertyDefinition property)
 {
     var c = new Rectangle
     {
         Stroke = Brushes.Black,
         StrokeThickness = 1,
         Width = 12,
         Height = 12,
         VerticalAlignment = VerticalAlignment.Center,
         HorizontalAlignment = HorizontalAlignment.Center
     };
     property.Converter = new ColorToBrushConverter();
     c.SetBinding(Shape.FillProperty, property.CreateBinding());
     return c;
 }
 /// <summary>
 /// Creates the color picker control.
 /// </summary>
 /// <param name="property">The property.</param>
 /// <returns></returns>
 protected virtual FrameworkElement CreateColorPickerControl(PropertyDefinition property)
 {
     var c = new ColorPicker2 { VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Stretch };
     c.SetBinding(ColorPicker2.SelectedColorProperty, property.CreateBinding());
     return c;
 }
        public FrameworkElement CreateExtendedToolkitControl(PropertyDefinition propertyDefinition, string bindingPath)
        {
            var propertyType = propertyDefinition.PropertyType;
            if (propertyType.Is(typeof(DateTime)))
            {
                var c = new DateTimePicker()
                {
                    VerticalAlignment = VerticalAlignment.Center,
                    HorizontalAlignment = HorizontalAlignment.Stretch,
                    IsReadOnly = propertyDefinition.IsReadOnly
                };
                c.SetBinding(DateTimePicker.ValueProperty, propertyDefinition.CreateBinding(bindingPath));
                return c;
            }

            if (propertyType.Is(typeof(TimeSpan)))
            {
                var c = new TimeSpanUpDown()
                {
                    VerticalAlignment = VerticalAlignment.Center,
                    HorizontalAlignment = HorizontalAlignment.Stretch,
                    IsReadOnly = propertyDefinition.IsReadOnly
                };
                c.SetBinding(TimeSpanUpDown.ValueProperty, propertyDefinition.CreateBinding(bindingPath));
                return c;
            }

            if (propertyType.Is(typeof(int)) || propertyType.Is(typeof(int?)))
            {
                var c = new CalculatorUpDown()
                {
                    VerticalAlignment = VerticalAlignment.Center,
                    HorizontalAlignment = HorizontalAlignment.Stretch,
                    Minimum = int.MinValue,
                    Maximum = int.MaxValue,
                    IsReadOnly = propertyDefinition.IsReadOnly
                };
                c.SetBinding(CalculatorUpDown.ValueProperty, propertyDefinition.CreateBinding(bindingPath));
                return c;
            }

            if (propertyType.Is(typeof(uint)) || propertyType.Is(typeof(uint?)))
            {
                var c = new CalculatorUpDown()
                {
                    VerticalAlignment = VerticalAlignment.Center,
                    HorizontalAlignment = HorizontalAlignment.Stretch,
                    Minimum = 0,
                    Maximum = uint.MaxValue,
                    IsReadOnly = propertyDefinition.IsReadOnly
                };
                c.SetBinding(CalculatorUpDown.ValueProperty, propertyDefinition.CreateBinding(bindingPath));
                return c;
            }

            if (propertyType.Is(typeof(decimal)) || propertyType.Is(typeof(decimal?)))
            {
                var c = new CalculatorUpDown()
                {
                    VerticalAlignment = VerticalAlignment.Center,
                    HorizontalAlignment = HorizontalAlignment.Stretch,
                    Minimum = decimal.MinValue,
                    Maximum = decimal.MaxValue,
                    IsReadOnly = propertyDefinition.IsReadOnly
                };
                c.SetBinding(CalculatorUpDown.ValueProperty, propertyDefinition.CreateBinding(bindingPath));
                return c;
            }

            if (propertyType.Is(typeof(Single)) || propertyType.Is(typeof(Single?)))
            {
                var c = new CalculatorUpDown()
                {
                    VerticalAlignment = VerticalAlignment.Center,
                    HorizontalAlignment = HorizontalAlignment.Stretch,
                    Minimum = decimal.MinValue,
                    Maximum = decimal.MaxValue,
                    IsReadOnly = propertyDefinition.IsReadOnly
                };
                c.SetBinding(CalculatorUpDown.ValueProperty, propertyDefinition.CreateBinding(bindingPath));
                return c;
            }

            if (propertyType.Is(typeof(double)) || propertyType.Is(typeof(double?)))
            {
                var c = new CalculatorUpDown()
                {
                    VerticalAlignment = VerticalAlignment.Center,
                    HorizontalAlignment = HorizontalAlignment.Stretch,
                    Minimum = decimal.MinValue,
                    Maximum = decimal.MaxValue,
                    IsReadOnly = propertyDefinition.IsReadOnly
                };
                c.SetBinding(CalculatorUpDown.ValueProperty, propertyDefinition.CreateBinding(bindingPath));
                return c;
            }

            if (propertyType.Is(typeof(Brush)))
            {
                var c = new ColorBox.ColorBox()
                {
                    VerticalAlignment = VerticalAlignment.Center,
                    HorizontalAlignment = HorizontalAlignment.Stretch,
                };
                c.SetBinding(ColorBox.ColorBox.BrushProperty, propertyDefinition.CreateBinding(bindingPath));
                return c;
            }

            if (propertyType.Is(typeof(Guid)) || propertyType.Is(typeof(Guid?)))
            {
                var c = new MaskedTextBox()
                {
                    VerticalAlignment = VerticalAlignment.Center,
                    HorizontalAlignment = HorizontalAlignment.Stretch,
                    Mask = "AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA",
                    IsReadOnly = propertyDefinition.IsReadOnly
                };
                c.SetBinding(MaskedTextBox.TextProperty, propertyDefinition.CreateBinding(bindingPath));
                return c;
            }

            if (propertyType.Is(typeof(char)) || propertyType.Is(typeof(char?)))
            {
                var c = new MaskedTextBox()
                {
                    VerticalAlignment = VerticalAlignment.Center,
                    HorizontalAlignment = HorizontalAlignment.Stretch,
                    Mask = "&",
                    IsReadOnly = propertyDefinition.IsReadOnly
                };
                c.SetBinding(MaskedTextBox.TextProperty, propertyDefinition.CreateBinding(bindingPath));
                return c;
            }

            return null;
        }