Exemplo n.º 1
0
 private static decimal LimitValueByBounds(decimal newValue, SpinnerControl control)
 {
     newValue = Math.Max(control.Minimum, Math.Min(control.Maximum, newValue));
     //  then ensure the number of decimal places is correct.
     newValue = Decimal.Round(newValue, control.DecimalPlaces);
     return(newValue);
 }
Exemplo n.º 2
0
        protected static void OnDecreaseCommand(Object sender, ExecutedRoutedEventArgs e)
        {
            SpinnerControl control = sender as SpinnerControl;

            if (control != null)
            {
                control.OnDecrease();
            }
        }
Exemplo n.º 3
0
        private static object CoerceValue(DependencyObject obj, object value)
        {
            decimal        newValue = (decimal)value;
            SpinnerControl control  = obj as SpinnerControl;

            if (control != null)
            {
                //  ensure that the value stays within the bounds of the minimum and
                //  maximum values that we define.
                newValue = LimitValueByBounds(newValue, control);
            }

            return(newValue);
        }
Exemplo n.º 4
0
        private static void OnValidationHasErrorPropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs args)
        {
            SpinnerControl control = sender as SpinnerControl;

            if (control != null)
            {
                var newValue = (bool)args.NewValue;
                var oldValue = (bool)args.OldValue;

                RoutedPropertyChangedEventArgs <bool> e =
                    new RoutedPropertyChangedEventArgs <bool>(oldValue, newValue, ValidationHasErrorEvent);

                control.OnValidationHasErrorPropertyChanged(e);
            }
        }
Exemplo n.º 5
0
        private static void OnFormattedValueChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
        {
            SpinnerControl control = obj as SpinnerControl;
            Decimal        number;

            if (control != null)
            {
                string newValue = (string)args.NewValue;
                string oldValue = (string)args.OldValue;

                if (Decimal.TryParse(newValue, out number))
                {
                    control.Value = number;
                }
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// If the value changes, update the text box that displays the Value
        /// property to the consumer.
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="args"></param>
        private static void OnValueChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args)
        {
            SpinnerControl control = obj as SpinnerControl;

            if (control != null)
            {
                var newValue = (decimal)args.NewValue;
                var oldValue = (decimal)args.OldValue;

                control.UpdateFormattedValue(newValue);

                RoutedPropertyChangedEventArgs <decimal> e =
                    new RoutedPropertyChangedEventArgs <decimal>(oldValue, newValue, ValueChangedEvent);

                control.OnValueChanged(e);
            }
        }
Exemplo n.º 7
0
        private void SpinnerTextBox_LostFocus(object sender, RoutedEventArgs e)
        {
            VOP.Controls.SpinnerControl spinnerCtl = sender as VOP.Controls.SpinnerControl;
            TextBox tb        = spinnerCtl.Template.FindName("tbTextBox", spinnerCtl) as TextBox;
            int     textValue = 0;

            if (!spinnerCtl.IsFocused)
            {
                if ("spinCtlEdge" == spinnerCtl.Name)
                {
                    if (int.TryParse(tb.Text, out textValue))
                    {
                        if (textValue > 2)
                        {
                            tb.Text = "2";
                        }
                        else if (textValue < -2)
                        {
                            tb.Text = "-2";
                        }
                    }
                    else
                    {
                        tb.Text = "0";
                    }
                }
                else if ("spinCtlSide2Side" == spinnerCtl.Name)
                {
                    if (int.TryParse(tb.Text, out textValue))
                    {
                        if (textValue > 6)
                        {
                            tb.Text = "6";
                        }
                        else if (textValue < -6)
                        {
                            tb.Text = "-6";
                        }
                    }
                    else
                    {
                        tb.Text = "0";
                    }
                }
                else if ("spinCtlDensity" == spinnerCtl.Name)
                {
                    if (int.TryParse(tb.Text, out textValue))
                    {
                        if (textValue > 3)
                        {
                            tb.Text = "3";
                        }
                        else if (textValue < -3)
                        {
                            tb.Text = "-3";
                        }
                    }
                    else
                    {
                        tb.Text = "0";
                    }
                }
                else if ("spinCtlHumidity" == spinnerCtl.Name)
                {
                    if (int.TryParse(tb.Text, out textValue))
                    {
                        if (textValue > 1)
                        {
                            tb.Text = "1";
                        }
                        else if (textValue < 0)
                        {
                            tb.Text = "0";
                        }
                    }
                    else
                    {
                        tb.Text = "0";
                    }
                }
            }
        }
Exemplo n.º 8
0
        private void EnableAllVisual(Visual myVisual, bool enable)
        {
            for (int i = 0; i < VisualTreeHelper.GetChildrenCount(myVisual); i++)
            {
                // Retrieve child visual at specified index value.
                Visual childVisual = (Visual)VisualTreeHelper.GetChild(myVisual, i);

                // Do processing of the child visual object.
                if (childVisual is SpinnerControl)
                {
                    SpinnerControl control = childVisual as SpinnerControl;

                    if (enable)
                    {
                        control.IsEnabled = true;
                    }
                    else
                    {
                        control.IsEnabled = false;
                    }

                    return;
                }
                else if (childVisual is CheckBox)
                {
                    CheckBox control = childVisual as CheckBox;

                    if (enable)
                    {
                        control.IsEnabled = true;
                    }
                    else
                    {
                        control.IsEnabled = false;
                    }

                    return;
                }
                else if (childVisual is TextBlock)
                {
                    TextBlock textBlock = childVisual as TextBlock;
                    if (enable)
                    {
                        SolidColorBrush brush = new SolidColorBrush();
                        Color           c     = new Color();
                        c.A = 255;
                        c.R = 14;
                        c.B = 14;
                        c.G = 14;

                        brush.Color          = c;
                        textBlock.Foreground = brush;

                        if (textElementIndex < colorList.Count)
                        {
                            textBlock.Foreground = colorList[textElementIndex];
                        }
                    }
                    else
                    {
                        //save enable color
                        if (textElementIndex < colorList.Count)
                        {
                            colorList[textElementIndex] = textBlock.Foreground;
                        }
                        else
                        {
                            colorList.Add(textBlock.Foreground);
                        }

                        SolidColorBrush brush = new SolidColorBrush();
                        Color           c     = new Color();
                        c.A = 100;
                        c.R = 14;
                        c.B = 14;
                        c.G = 14;

                        brush.Color          = c;
                        textBlock.Foreground = brush;
                    }

                    textElementIndex++;
                }
                else if (childVisual is ComboBox)
                {
                    ComboBox combobox = childVisual as ComboBox;
                    if (enable)
                    {
                        SolidColorBrush brush = new SolidColorBrush();
                        Color           c     = new Color();
                        c.A = 255;
                        c.R = 14;
                        c.B = 14;
                        c.G = 14;

                        brush.Color         = c;
                        combobox.Foreground = brush;
                    }
                    else
                    {
                        SolidColorBrush brush = new SolidColorBrush();
                        Color           c     = new Color();
                        c.A = 100;
                        c.R = 14;
                        c.B = 14;
                        c.G = 14;

                        brush.Color         = c;
                        combobox.Foreground = brush;
                    }
                }

                // Enumerate children of the child visual object.
                EnableAllVisual(childVisual, enable);
            }
        }