private static decimal LimitValueByBounds(decimal newValue, SpinnerControlOnlySupportUpDowmKey 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 OnDecreaseCommand(Object sender, ExecutedRoutedEventArgs e) { SpinnerControlOnlySupportUpDowmKey control = sender as SpinnerControlOnlySupportUpDowmKey; if (control != null) { control.OnDecrease(); } }
private static object CoerceValue(DependencyObject obj, object value) { decimal newValue = (decimal)value; SpinnerControlOnlySupportUpDowmKey control = obj as SpinnerControlOnlySupportUpDowmKey; 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); }
private static void OnValidationHasErrorPropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs args) { SpinnerControlOnlySupportUpDowmKey control = sender as SpinnerControlOnlySupportUpDowmKey; 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); } }
private static void OnFormattedValueChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args) { SpinnerControlOnlySupportUpDowmKey control = obj as SpinnerControlOnlySupportUpDowmKey; Decimal number; if (control != null) { string newValue = (string)args.NewValue; string oldValue = (string)args.OldValue; if (Decimal.TryParse(newValue, out number)) { control.Value = number; } } }
/// <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) { SpinnerControlOnlySupportUpDowmKey control = obj as SpinnerControlOnlySupportUpDowmKey; 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); } }