Beispiel #1
0
        private void DecreaseMask(int position, int length)
        {
            var decPos = GetDecimalSeparatorPosition(Mask);
            var str    = MaskProvider.ToDisplayString();

            if (position > decPos)
            {
                Text       = str.Remove(position, length).Insert(position, 0.ToString("D" + length));
                CaretIndex = position;
                return;
            }

            if (position + length > decPos)
            {
                var decLength   = position + length - decPos - 1;
                var decPosition = decPos + 1;
                str = str.Remove(decPosition, decLength).Insert(decPosition, 0.ToString("D" + decLength));

                length = decPos - position;
            }

            if (length > 0)
            {
                str = str.Remove(position, length).Replace(" ", string.Empty);
                if (str.Length == 0)
                {
                    str = PromptChar.ToString();
                }

                var mask = FormatMask(Mask.Remove(position, length));
                if (mask.Length == 0 || mask.StartsWith("."))
                {
                    if (mask.StartsWith("."))
                    {
                        str = PromptChar + str;
                    }

                    mask = PromptChar + mask;
                }

                Mask = mask;

                Text = str;
            }

            CaretIndex = position;
        }
        private string ConvertValueToText(object value)
        {
            if (value == null)
            {
                value = string.Empty;
            }

            if (_convertExceptionOccurred)
            {
                value = Value;
                _convertExceptionOccurred = false;
            }

            //I have only seen this occur while in Blend, but we need it here so the Blend designer doesn't crash.
            if (MaskProvider == null)
            {
                return(value.ToString());
            }

            MaskProvider.Set(value.ToString());
            return(MaskProvider.ToDisplayString());
        }