static void OnDisplayFormatChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) { DecimalBox me = sender as DecimalBox; if (me != null) { me.SetDisplay(); } }
static object OnCoerceValueChanged(DependencyObject sender, object value) { decimal retVal = (decimal)value; DecimalBox me = sender as DecimalBox; bool valueModified = false; if (me != null) { if (me.MaxNumber != null) { if (retVal > me.MaxNumber.Value) { retVal = me.MaxNumber.Value; valueModified = true; } } if (me.MinNumber != null) { if (retVal < me.MinNumber.Value) { retVal = me.MinNumber.Value; valueModified = true; } } if (me.NumberOfDecimalDigit != null) { string[] wrk = retVal.ToString(System.Globalization.CultureInfo.CurrentCulture).Split('.'); int numDigs = 0; if (wrk.Length > 1) { numDigs = wrk[1].Length; } if (numDigs > me.NumberOfDecimalDigit.Value) { retVal = Math.Floor(decimal.Multiply(retVal, Convert.ToDecimal(Math.Pow(10, me.NumberOfDecimalDigit.Value)))) / Convert.ToDecimal(Math.Pow(10, me.NumberOfDecimalDigit.Value)); valueModified = true; } } if (valueModified) { me.WorkValue = retVal.ToString(System.Globalization.CultureInfo.CurrentCulture); me.SetDisplay(); } } return(retVal); }
static void OnValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) { DecimalBox me = sender as DecimalBox; if (me != null) { if (!me.SettingValues) { me.SettingValues = true; me.WorkValue = me.Value.ToString(System.Globalization.CultureInfo.CurrentCulture); me.SettingValues = false; } me.SetDisplay(); me.RaiseEvent(new RoutedEventArgs(ValueChangedEvent)); } }