0

我有一个简单的应用程序,它有一个TextBox和一个Canvas. 当用户触摸 时Canvas,我想将焦点移到TextBox。所以,在PointerReleased活动中,我得到了:

private void canvas_PointerReleased(object sender, PointerRoutedEventArgs e)
        {
            textBoxMain.Focus(Windows.UI.Xaml.FocusState.Programmatic);
        }

我还订阅了TextBox GotFocusandLostFocus并注意到,在TextBox获得焦点之后,它立即失去了焦点。为什么会失去焦点,我该如何解决?

提前致谢。

4

1 回答 1

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);
}
于 2013-10-03T19:39:26.670 回答