예제 #1
0
        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);
        }
예제 #2
0
        private static void ValuePropertyChangedCallback(object sender, DependencyPropertyChangedEventArgs e)
        {
            ValueRangeTextBox valueRangeTextBox = sender as ValueRangeTextBox;

            if (valueRangeTextBox.IsForcingValue)
            {
                return;
            }

            // The ValueChangedCallback can be raised even though both values are the same since the property
            // datatype is Object.
            if (object.Equals(e.NewValue, e.OldValue))
            {
                return;
            }

            valueRangeTextBox.IsInValueChanged = true;
            try
            {
                valueRangeTextBox.Text = valueRangeTextBox.GetTextFromValue(e.NewValue);
            }
            finally
            {
                valueRangeTextBox.IsInValueChanged = false;
            }
        }
예제 #3
0
        protected override void OnInitialized(EventArgs e)
        {
            this.IsFinalizingInitialization = true;
            try
            {
                this.CoerceValue(ValueRangeTextBox.ValueDataTypeProperty);

                this.IsNumericValueDataType = ValueRangeTextBox.IsNumericType(this.ValueDataType);
                this.RefreshConversionHelpers();

                this.CoerceValue(ValueRangeTextBox.MinValueProperty);
                this.CoerceValue(ValueRangeTextBox.MaxValueProperty);

                this.CoerceValue(ValueRangeTextBox.ValueProperty);

                this.CoerceValue(ValueRangeTextBox.NullValueProperty);

                this.CoerceValue(ValueRangeTextBox.TextProperty);
            }
            catch (Exception exception)
            {
                throw new InvalidOperationException("Initialization of the ValueRangeTextBox failed.", exception);
            }
            finally
            {
                this.IsFinalizingInitialization = false;
            }

            base.OnInitialized(e);
        }
예제 #4
0
        private static void FormatProviderPropertyChangedCallback(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            ValueRangeTextBox valueRangeTextBox = (ValueRangeTextBox)sender;

            if (!valueRangeTextBox.IsInitialized)
            {
                return;
            }

            valueRangeTextBox.OnFormatProviderChanged();
        }
예제 #5
0
        private static void ValueDataTypePropertyChangedCallback(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            ValueRangeTextBox valueRangeTextBox = sender as ValueRangeTextBox;

            Type valueDataType = e.NewValue as Type;

            valueRangeTextBox.IsNumericValueDataType = ValueRangeTextBox.IsNumericType(valueDataType);

            valueRangeTextBox.RefreshConversionHelpers();

            valueRangeTextBox.ConvertValuesToDataType(valueDataType);
        }
예제 #6
0
        private static object TextCoerceValueCallback(object sender, object value)
        {
            ValueRangeTextBox valueRangeTextBox = sender as ValueRangeTextBox;

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

            if (value == null)
            {
                return(string.Empty);
            }

            return(value);
        }
예제 #7
0
        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);
        }
예제 #8
0
        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);
            }
        }
예제 #9
0
        private static void NullValuePropertyChangedCallback(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            ValueRangeTextBox valueRangeTextBox = sender as ValueRangeTextBox;

            if (e.OldValue == null)
            {
                if (valueRangeTextBox.Value == null)
                {
                    valueRangeTextBox.RefreshValue();
                }
            }
            else
            {
                if (e.OldValue.Equals(valueRangeTextBox.Value))
                {
                    valueRangeTextBox.RefreshValue();
                }
            }
        }
예제 #10
0
        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);
        }
예제 #11
0
        private static object ValueDataTypeCoerceValueCallback(DependencyObject sender, object value)
        {
            ValueRangeTextBox valueRangeTextBox = sender as ValueRangeTextBox;

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

            Type valueDataType = value as Type;

            try
            {
                valueRangeTextBox.ValidateDataType(valueDataType);
            }
            catch (Exception exception)
            {
                throw new ArgumentException("An error occured while trying to change the ValueDataType.", exception);
            }

            return(value);
        }