private static object NullValueCoerceValueCallback(DependencyObject sender, object value)
        {
            ValueRangeTextBox valueRangeTextBox = sender as ValueRangeTextBox;

            if (!valueRangeTextBox.IsInitialized)
            {
                return(DependencyProperty.UnsetValue);
            }

            if ((value == null) || (value == DBNull.Value))
            {
                return(value);
            }

            Type type = valueRangeTextBox.ValueDataType;

            if (type == null)
            {
                throw new InvalidOperationException("An attempt was made to set a null value when the ValueDataType property is null.");
            }

            if (valueRangeTextBox.IsFinalizingInitialization)
            {
                value = ValueRangeTextBox.ConvertValueToDataType(value, valueRangeTextBox.ValueDataType);
            }

            if (value.GetType() != type)
            {
                throw new ArgumentException("The value is not of type " + type.Name + ".", "NullValue");
            }

            return(value);
        }
        private static object MaxValueCoerceValueCallback(DependencyObject sender, object value)
        {
            ValueRangeTextBox valueRangeTextBox = sender as ValueRangeTextBox;

            if (!valueRangeTextBox.IsInitialized)
            {
                return(DependencyProperty.UnsetValue);
            }

            if (value == null)
            {
                return(value);
            }

            Type type = valueRangeTextBox.ValueDataType;

            if (type == null)
            {
                throw new InvalidOperationException("An attempt was made to set a maximum value when the ValueDataType property is null.");
            }

            if (valueRangeTextBox.IsFinalizingInitialization)
            {
                value = ValueRangeTextBox.ConvertValueToDataType(value, valueRangeTextBox.ValueDataType);
            }

            if (value.GetType() != type)
            {
                throw new ArgumentException("The value is not of type " + type.Name + ".", "MinValue");
            }

            IComparable comparable = value as IComparable;

            if (comparable == null)
            {
                throw new InvalidOperationException("MaxValue does not implement the IComparable interface.");
            }

            object minValue = valueRangeTextBox.MinValue;

            // ValidateValueInRange will throw if it must.
            valueRangeTextBox.ValidateValueInRange(minValue, value, valueRangeTextBox.Value);

            return(value);
        }
        private void ConvertValuesToDataType(Type type)
        {
            if (type == null)
            {
                this.MinValue  = null;
                this.MaxValue  = null;
                this.NullValue = null;

                this.Value = null;

                return;
            }

            object minValue = this.MinValue;

            if ((minValue != null) && (minValue.GetType() != type))
            {
                this.MinValue = ValueRangeTextBox.ConvertValueToDataType(minValue, type);
            }

            object maxValue = this.MaxValue;

            if ((maxValue != null) && (maxValue.GetType() != type))
            {
                this.MaxValue = ValueRangeTextBox.ConvertValueToDataType(maxValue, type);
            }

            object nullValue = this.NullValue;

            if (((nullValue != null) && (nullValue != DBNull.Value)) &&
                (nullValue.GetType() != type))
            {
                this.NullValue = ValueRangeTextBox.ConvertValueToDataType(nullValue, type);
            }

            object value = this.Value;

            if (((value != null) && (value != DBNull.Value)) &&
                (value.GetType() != type))
            {
                this.Value = ValueRangeTextBox.ConvertValueToDataType(value, type);
            }
        }
        private static object ValueCoerceValueCallback(object sender, object value)
        {
            ValueRangeTextBox valueRangeTextBox = sender as ValueRangeTextBox;

            if (!valueRangeTextBox.IsInitialized)
            {
                return(DependencyProperty.UnsetValue);
            }

            if (valueRangeTextBox.IsFinalizingInitialization)
            {
                value = ValueRangeTextBox.ConvertValueToDataType(value, valueRangeTextBox.ValueDataType);
            }

            if (!valueRangeTextBox.IsForcingValue)
            {
                valueRangeTextBox.ValidateValue(value);
            }

            return(value);
        }