2016-01-19 15 views
6

Tôi có biểu mẫu đơn giản và tôi muốn khi người dùng nhấn vào bàn phím điện thoại, con trỏ sẽ chuyển đến hộp văn bản tiếp theo. Điều này có thể thực hiện được trong Universal Windows Apps không? Trong android bàn phím hiển thị phím Kế tiếp/Xong để điều hướng trong các phần tử biểu mẫu.Di chuyển đến hộp văn bản tiếp theo khi nhấn phím 'Enter' thay vì gửi (Windows Phone)

enter image description here

Trả lời

7

Bạn có thể sử dụng FocusManager để di chuyển trọng tâm theo chương trình.

Sử dụng sự kiện KeyDown của vùng chứa Hộp văn bản, giả sử, một StackPanel, để nghe sự kiện bàn phím của bạn. Vì vậy, mã của bạn sẽ làm việc như cách này

private void stackPanel_KeyDown(object sender, KeyRoutedEventArgs e) 
    { 
     if (e.Key == Windows.System.VirtualKey.Enter) 
     { 
      if (FocusManager.GetFocusedElement() == inputTextBox) // Change the inputTextBox to your TextBox name 
      { 
       FocusManager.TryMoveFocus(FocusNavigationDirection.Next); 
       FocusManager.TryMoveFocus(FocusNavigationDirection.Next); 
      } 
      else 
      { 
       FocusManager.TryMoveFocus(FocusNavigationDirection.Next); 
      } 

      // Make sure to set the Handled to true, otherwise the RoutedEvent might fire twice 
      e.Handled = true; 
     } 
    } 

Để biết thêm chi tiết về FocusManager, xem để https://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.input.focusmanager.trymovefocus

Để biết thêm chi tiết về KeyDown, xem để https://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.uielement.keydown

+0

Điều duy nhất mà vẫn còn gây phiền hà cho tôi là, tại sao bạn gán nó cho StackPanel thay vì hộp văn bản như: '' –

+0

Vì vậy, chỉ có nút enter và không thực hiện/nút tiếp theo? – testing

0

làm bạn có cái gì đó như yourTextBoxName.Focus() ..? cũng sử dụng KeyDownEvent cho New Password textbox và kiểm tra như sau

if (e.Key == Key.Enter || e.PlatformKeyCode == 0x0A) 
{ 
    confirmPassword.Focus();//change confirmPassword to your controls actual name  
} 
Các vấn đề liên quan