我有一个简单的应用程序,其中包含TextBox
和Canvas
。当用户触摸Canvas
时,我想将焦点移至TextBox
。所以,在PointerReleased
事件中,我得到了:
private void canvas_PointerReleased(object sender, PointerRoutedEventArgs e)
{
textBoxMain.Focus(Windows.UI.Xaml.FocusState.Programmatic);
}
我还订阅了TextBox GotFocus
和LostFocus
并注意到,在TextBox
集中注意力之后,它立即失去焦点。为什么它失去了焦点,我该如何解决呢?
提前致谢。
答案 0 :(得分:1)
这对我有用。
private void Canvas_PointerReleased(object sender, PointerRoutedEventArgs e)
{
textBoxMain.Focus(Windows.UI.Xaml.FocusState.Programmatic);
}
private void textBoxMain_GotFocus(object sender, RoutedEventArgs e)
{
textBoxMain.Focus(Windows.UI.Xaml.FocusState.Programmatic);
}