protected virtual bool QueryValueFromTextCore(string text, out object value)
        {
            value = null;

            Type validatingType = this.ValueDataType;

            text = text.Trim();

            if (validatingType == null)
            {
                return(true);
            }

            if (!validatingType.IsValueType && (validatingType != typeof(string)))
            {
                return(false);
            }

            try
            {
                value = ChangeTypeHelper.ChangeType(text, validatingType, this.GetActiveFormatProvider());
            }
            catch
            {
                if (this.BeepOnError)
                {
                    System.Media.SystemSounds.Beep.Play();
                }
                return(false);
            }

            return(true);
        }
        private static object ConvertValueToDataType(object value, Type type)
        {
            // We use InvariantCulture instead of the active format provider since the FormatProvider is only
            // used when the source type is String.  When we are converting from a string, we are
            // actually converting a value from XAML.  Therefore, if the string will have a period as a
            // decimal separator.  If we were using the active format provider, we could end up expecting a coma
            // as the decimal separator and the ChangeType method would throw.
            if (type == null)
            {
                return(null);
            }

            if (((value != null) && (value != DBNull.Value)) &&
                (value.GetType() != type))
            {
                return(ChangeTypeHelper.ChangeType(value, type, CultureInfo.InvariantCulture));
            }

            return(value);
        }