public static IObservable <double> SelectValueChanges(SpinnerControl spinnerControl)
 {
     return(Observable.FromEventPattern <
                RoutedPropertyChangedEventHandler <decimal>,
                RoutedPropertyChangedEventArgs <double> >(a => spinnerControl.ValueChanged += a, a => spinnerControl.ValueChanged += a)
            .Select(a => a.EventArgs.NewValue));
 }
 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);
 }
        protected static void OnIncreaseCommand(object sender, ExecutedRoutedEventArgs e)
        {
            SpinnerControl control = sender as SpinnerControl;

            if (control != null)
            {
                control.OnIncrease();
            }
        }
        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);
        }
        /// <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.RaiseEvent(e);
            }
        }