Windows应用商店应用文本框不断失去焦点

时间:2013-10-03 19:22:02

标签: c# wpf microsoft-metro windows-store-apps

我有一个简单的应用程序,其中包含TextBoxCanvas。当用户触摸Canvas时,我想将焦点移至TextBox。所以,在PointerReleased事件中,我得到了:

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

我还订阅了TextBox GotFocusLostFocus并注意到,在TextBox集中注意力之后,它立即失去焦点。为什么它失去了焦点,我该如何解决呢?

提前致谢。

1 个答案:

答案 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);
}