private void Code_OnKeyDown(object sender, KeyEventArgs args) { if (args.Key == Key.Enter) { PhoneNumberLabel.Focus(); PhoneNumberLabel.SelectionStart = PhoneNumberLabel.Text.Length; } if (args.Key == Key.D8 || // * args.Key == Key.Unknown || // +(long tap on 0) or -/. args.Key == Key.D3 || // # args.Key == Key.A) { args.Handled = true; } if (args.Key == Key.Space) { args.Handled = true; PhoneNumberLabel.Focus(); } if (args.Key >= Key.NumPad0 && args.Key <= Key.NumPad9 && PCode.Text.Length == 3) { var codeTail = string.Empty; if (ViewModel.IsPhoneCodeInvalid) { var countryCode2 = CountryUtils.CountriesSource.FirstOrDefault(x => x.PhoneCode == PCode.Text.Substring(0, 2)); if (countryCode2 != null) { codeTail = PCode.Text.Substring(2, 1); PCode.Text = PCode.Text.Substring(0, 2); } var countryCode1 = CountryUtils.CountriesSource.FirstOrDefault(x => x.PhoneCode == PCode.Text.Substring(0, 1)); if (countryCode1 != null) { codeTail = PCode.Text.Substring(1, 2); PCode.Text = PCode.Text.Substring(0, 1); } } args.Handled = true; PhoneNumberLabel.Text = codeTail + args.Key.ToString().Replace("NumPad", string.Empty) + PhoneNumberLabel.Text; PhoneNumberLabel.SelectionStart = codeTail.Length + 1; PhoneNumberLabel.Focus(); } }