예제 #1
0
        public static UIElement CreateSpinner(object source, string path, AnnotationVariable var, object storedValue)
        {
            if (var.DataType.IsIntegral())
            {
                IntegerUpDown spinner = new IntegerUpDown();
                spinner.Increment = var.GetStepInteger();
                spinner.Minimum   = var.GetMinimumInteger();
                spinner.Maximum   = var.GetMaximumInteger();

                Binding binding = new Binding();
                binding.Source = source;
                binding.Mode   = BindingMode.TwoWay;
                binding.Path   = new PropertyPath(path);

                BindingOperations.SetBinding(spinner, IntegerUpDown.ValueProperty, binding);
                if (storedValue == null)
                {
                    spinner.Value = Math.Max(Math.Min(0, spinner.Maximum.Value), spinner.Minimum.Value);
                }
                else
                {
                    spinner.Value = (int)storedValue;
                }
                spinner.HorizontalContentAlignment = HorizontalAlignment.Stretch;
                spinner.HorizontalAlignment        = HorizontalAlignment.Stretch;

                return(spinner);
            }
            else
            {
                DoubleUpDown spinner = new DoubleUpDown();
                spinner.Increment = var.GetStepDouble();
                spinner.Minimum   = var.GetMinimumDouble();
                spinner.Maximum   = var.GetMaximumDouble();


                Binding binding = new Binding();
                binding.Source = source;
                binding.Mode   = BindingMode.TwoWay;
                binding.Path   = new PropertyPath(path);

                BindingOperations.SetBinding(spinner, DoubleUpDown.ValueProperty, binding);
                if (storedValue == null)
                {
                    spinner.Value = Math.Max(Math.Min(0, spinner.Maximum.Value), spinner.Minimum.Value);
                }
                else
                {
                    spinner.Value = (double)storedValue;
                }
                spinner.HorizontalContentAlignment = HorizontalAlignment.Stretch;
                spinner.HorizontalAlignment        = HorizontalAlignment.Stretch;

                return(spinner);
            }
        }
예제 #2
0
        public static UIElement CreateSlider(object source, string path, AnnotationVariable var, object storedValue)
        {
            Slider slider = new Slider();

            slider.Minimum       = (var.DataType.IsIntegral()) ? var.GetMinimumInteger() : var.GetMinimumDouble();
            slider.Maximum       = (var.DataType.IsIntegral()) ? var.GetMaximumInteger() : var.GetMaximumDouble();
            slider.TickFrequency = (var.DataType.IsIntegral()) ? var.GetStepInteger() : var.GetStepDouble();

            slider.IsSnapToTickEnabled        = true;
            slider.HorizontalContentAlignment = HorizontalAlignment.Stretch;
            slider.HorizontalAlignment        = HorizontalAlignment.Stretch;
            slider.Width = 250;
            Binding binding = new Binding();

            binding.Source = source;
            binding.Mode   = BindingMode.TwoWay;
            binding.Path   = new PropertyPath(path);

            BindingOperations.SetBinding(slider, RangeBase.ValueProperty, binding);
            if (storedValue == null)
            {
                slider.Value = Math.Max(Math.Min(0.0, slider.Maximum), slider.Minimum);
            }
            else
            {
                slider.Value = (double)storedValue;
            }
            return(slider);
        }