Bạn có thể xử lý các KeyDown/KeyUp sự kiện trên textbox của bạn (tùy thuộc vào việc bạn muốn đi đến tiếp theo ở đầu hoặc cuối của báo chí key).
Ví dụ XAML:
<TextBox KeyUp="TextBox_KeyUp" />
Mã Đằng sau:
private void TextBox_KeyUp(object sender, KeyRoutedEventArgs e)
{
TextBox tbSender = (TextBox)sender;
if (e.Key == Windows.System.VirtualKey.Enter)
{
// Get the next TextBox and focus it.
DependencyObject nextSibling = GetNextSiblingInVisualTree(tbSender);
if (nextSibling is Control)
{
// Transfer "keyboard" focus to the target element.
((Control)nextSibling).Focus(FocusState.Keyboard);
}
}
}
Toàn mã ví dụ bao gồm cả mã cho GetNextSiblingInVisualTree (phương pháp helper): https://github.com/finnigantime/Samples/tree/master/examples/Win8Xaml/TextBox_EnterMovesFocusToNextControl
Lưu ý rằng gọi Focus() với FocusState.Keyboard hiển thị tiêu điểm chấm xung quanh các yếu tố có một rect trong mẫu kiểm soát của chúng (e. g. Nút). Gọi Focus() với FocusState.Pointer không hiển thị tiêu điểm rect (bạn đang sử dụng touch/mouse, vì vậy bạn biết bạn đang tương tác với phần tử nào).
Nguồn
2013-07-14 19:33:27
Cảm ơn Patrick. Nó hoạt động một điều trị. – Sun