我想在用户在我的应用程序中的任何位置开始输入时给出文本框焦点。将焦点放在按键上的文本框
我的页面从LayoutAwarePage继承。
这可以实现吗?
编辑: 我得到这个代码:
// In constructor
Window.Current.CoreWindow.KeyDown += CoreWindow_KeyDown;
// Somewhere else in class
void CoreWindow_KeyDown(Windows.UI.Core.CoreWindow sender, Windows.UI.Core.KeyEventArgs args)
{
this.setSearchboxFocus((int)args.VirtualKey);
}
private void setSearchboxFocus(int keyCode)
{
if (keyCode == 38)
return;
if (keyCode == 40)
return;
if (this.searchBox.FocusState == Windows.UI.Xaml.FocusState.Unfocused)
{
this.searchBox.Text = "";
this.searchBox.Focus(Windows.UI.Xaml.FocusState.Keyboard);
}
}
我似乎无法找到任何ProcessCmdKey从Page覆盖。 – 2013-04-11 16:33:25