/// <summary>
        /// Ensure the new value of Increment dependency property change is valid,
        /// or revert the change and throw an exception.
        /// </summary>
        /// <param name="d">The DependencyObject whose DependencyProperty is changed.</param>
        /// <param name="e">The DependencyPropertyChangedEventArgs.</param>
        private static void EnsureValidIncrementValue(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            NumericUpDown nud = (NumericUpDown)d;
            double        number;

            if (!IsValidDoubleValue(e.NewValue, out number) || number <= 0)
            {
                // revert back to old value.
                nud._levelsFromRootCall++;
                nud.SetValue(e.Property, e.OldValue);
                nud._levelsFromRootCall--;

                // throw ArgumentException
                string message = string.Format(
                    CultureInfo.InvariantCulture,
                    Properties.Resources.NumericUpDown_EnsureValidIncrementValue_InvalidValue,
                    e.NewValue);
                throw new ArgumentException(message, "e");
            }
        }
        /// <summary>
        /// Ensure the new value of a dependency property change is a valid double value,
        /// or revert the change and throw an exception.
        /// </summary>
        /// <param name="d">The DependencyObject whose DependencyProperty is changed.</param>
        /// <param name="property">The DependencyProperty that changed.</param>
        /// <param name="oldValue">The old value.</param>
        /// <param name="newValue">The new value.</param>
        private static void EnsureValidDoubleValue(DependencyObject d, DependencyProperty property, object oldValue, object newValue)
        {
            NumericUpDown nud = d as NumericUpDown;
            double        number;

            if (!IsValidDoubleValue(newValue, out number))
            {
                // revert back to old value
                nud._levelsFromRootCall++;
                nud.SetValue(property, oldValue);
                nud._levelsFromRootCall--;

                // throw ArgumentException
                string message = string.Format(
                    CultureInfo.InvariantCulture,
                    Properties.Resources.NumericUpDown_EnsureValidDoubleValue_InvalidDoubleValue,
                    newValue);
                throw new ArgumentException(message, "newValue");
            }
        }