예제 #1
0
        private FrameworkElement GenerateCalculator(PropertyInfo property, Binding binding)
        {
#if !SILVERLIGHT
            CalculatorUpDown calculatorUpDown = new CalculatorUpDown()
            {
                Margin = new Thickness(0, 3, 18, 3)
            };
            calculatorUpDown.IsReadOnly = !(bindables[property.Name].Direction == BindingDirection.TwoWay);
            // Binding
            this.bindings.Add(property.Name, calculatorUpDown.SetBinding(CalculatorUpDown.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);
        }
예제 #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);
        }