Ejemplo n.º 1
0
        public void VerifyChar()
        {
            var maskedTextProvider = new MaskedTextProvider(TestSimpleDigitMask);

            Assert.True(maskedTextProvider.VerifyChar('1', 0, out MaskedTextResultHint resultHint));
            Assert.Equal(MaskedTextResultHint.Success, resultHint);
            Assert.False(maskedTextProvider.VerifyChar('T', 0, out resultHint));
            Assert.Equal(MaskedTextResultHint.DigitExpected, resultHint);
        }
Ejemplo n.º 2
0
        protected override void OnPreviewTextInput(TextCompositionEventArgs e)
        {
            e.Handled = true;
            var validInput = false;

            if (!string.IsNullOrWhiteSpace(e.Text) && e.Text.Length == 1)
            {
                MaskedTextResultHint hint;
                validInput = MaskProvider.VerifyChar(e.Text[0], SelectionStart, out hint);
                if (validInput)
                {
                    var initialString = MaskProvider.ToDisplayString();
                    var charArray     = initialString.ToCharArray();
                    charArray[SelectionStart] = e.Text[0];
                    var verifyString = new string(charArray);

                    TimeSpan ts;
                    if (TimeSpan.TryParse(verifyString, CultureInfo.CurrentCulture, out ts))
                    {
                        MaskProvider.Replace(e.Text, SelectionStart);
                    }
                    else
                    {
                        // Case 08:00:00 => 28:00:00 => 20:00:00
                        if (SelectionStart + 1 < charArray.Length)
                        {
                            charArray[SelectionStart + 1] = '0';
                            verifyString = new string(charArray);
                            if (TimeSpan.TryParse(verifyString, CultureInfo.CurrentCulture, out ts))
                            {
                                MaskProvider.Replace(e.Text, SelectionStart);
                                MaskProvider.Replace('0', SelectionStart + 1);
                            }
                            else
                            {
                                validInput = false;
                            }
                        }
                        else
                        {
                            validInput = false;
                        }
                    }
                }
            }
            base.OnPreviewTextInput(e);
            if (validInput)
            {
                RefreshText();
                SelectionStart = GetNextCharacterPosition(SelectionStart);
            }
        }
Ejemplo n.º 3
0
        protected override void OnPreviewTextInput(TextCompositionEventArgs e)
        {
            System.ComponentModel.MaskedTextResultHint hint;
            int TestPosition;

            if (e.Text.Length == 1)
            {
                this._NewTextIsOk = _mprovider.VerifyChar(e.Text[0], this.CaretIndex, out hint);
            }
            else
            {
                this._NewTextIsOk = _mprovider.VerifyString(e.Text, out TestPosition, out hint);
            }

            base.OnPreviewTextInput(e);
        }