Пример #1
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            FlatButtonStyle.Green.ApplyTo(btnPair);

            lblInstructions.Text = Localize.GetValue("ManualPairingForRideLinQ_Instructions");

            btnPair.SetTitle(Localize.GetValue("ManualPairingForRideLinQ_Pair"), UIControlState.Normal);
            FlatButtonStyle.Green.ApplyTo(btnPair);

            // to hide keyboard when touch
            btnPair.TouchUpInside += (object sender, EventArgs e) => {
                PairingCode1.ResignFirstResponder();
                PairingCode2.ResignFirstResponder();
            };

            var bindingSet = this.CreateBindingSet <ManualPairingForRideLinqView, ManualPairingForRideLinqViewModel>();

            bindingSet.Bind(PairingCode1)
            .To(vm => vm.PairingCodeLeft);

            bindingSet.Bind(PairingCode2)
            .To(vm => vm.PairingCodeRight);

            bindingSet.Bind(btnPair)
            .For(v => v.Command)
            .To(vm => vm.PairWithRideLinq);

            bindingSet.Apply();

            // Set focus on text box
            PairingCode1.BecomeFirstResponder();

            PairingCode1.ShouldChangeCharacters = (field, range, s) => CheckMaxLength(field, range, s, PairingCode1MaxLength, MoveToPairingCode2);
            PairingCode2.ShouldChangeCharacters = (field, range, s) => CheckMaxLength(field, range, s, PairingCode2MaxLength);

            PairingCode1.EditingChanged += (sender, e) =>
            {
                if (PairingCode1.Text.Length == PairingCode1MaxLength)
                {
                    PairingCode2.BecomeFirstResponder();
                }
            };

            PairingCode2.EditingChanged += (sender, e) =>
            {
                if (PairingCode2.Text.Length == 0)
                {
                    PairingCode1.BecomeFirstResponder();
                }
            };
        }
Пример #2
0
        private void MoveToPairingCode2(string value)
        {
            var length = value.HasValue() ? value.Length : 0;

            var caretPosition = PairingCode1.GetOffsetFromPosition(PairingCode1.BeginningOfDocument, PairingCode1.SelectedTextRange.Start);

            var isCaretAtEnd = caretPosition == PairingCode1MaxLength;

            if (PairingCode2.Text.Length + length <= PairingCode2MaxLength && isCaretAtEnd)
            {
                PairingCode2.Text = value + PairingCode2.Text;
                PairingCode2.BecomeFirstResponder();
            }
        }