Esempio n. 1
0
        public void Clear()
        {
            var maskedTextProvider = new MaskedTextProvider(TestSimpleDigitMask);

            maskedTextProvider.Add("12");
            Assert.Equal(2, maskedTextProvider.AssignedEditPositionCount);

            maskedTextProvider.Clear();
            Assert.Equal(0, maskedTextProvider.AssignedEditPositionCount);
        }
Esempio n. 2
0
        public void Clear_MaskedTextResultHint()
        {
            var maskedTextProvider = new MaskedTextProvider(TestSimpleDigitMask);

            maskedTextProvider.Clear(out MaskedTextResultHint resultHint);
            Assert.Equal(MaskedTextResultHint.NoEffect, resultHint);

            maskedTextProvider.Add("12");
            Assert.Equal(2, maskedTextProvider.AssignedEditPositionCount);

            maskedTextProvider.Clear(out resultHint);
            Assert.Equal(MaskedTextResultHint.Success, resultHint);
            Assert.Equal(0, maskedTextProvider.AssignedEditPositionCount);
        }
Esempio n. 3
0
        protected override void OnPreviewLostKeyboardFocus(KeyboardFocusChangedEventArgs e)
        {
            if (StayInFocusUntilValid)
            {
                _mprovider.Clear();
                _mprovider.Add(this.Text);
                if (!_mprovider.MaskFull)
                {
                    e.Handled = true;
                }
            }

            base.OnPreviewLostKeyboardFocus(e);
        }
Esempio n. 4
0
        private void InputText(string text)
        {
            string input = text;

            int testPosition;
            MaskedTextResultHint resultHint;
            bool result;

            if (RejectInputOnFirstFailure)
            {
                result = provider.Set(input, out testPosition, out resultHint);
                if (!result)
                {
                    OnMaskInputRejected(new MaskInputRejectedEventArgs(testPosition, resultHint));
                }
            }
            else
            {
                provider.Clear();
                testPosition = 0;

                // Unfortunately we can't break if we reach the end of the mask, since
                // .net iterates over _all_ the chars in the input
                for (int i = 0; i < input.Length; i++)
                {
                    char c = input [i];

                    result = provider.InsertAt(c, testPosition, out testPosition, out resultHint);
                    if (result)
                    {
                        testPosition++;                         // Move to the next free position
                    }
                    else
                    {
                        OnMaskInputRejected(new MaskInputRejectedEventArgs(testPosition, resultHint));
                    }
                }
            }
        }