KeyDown Event is not responding till any user control is clicked or setFocus implicitly . I want to fire the key event after the page loads , anytime.
I tried like :
private void Page_KeyDown(obje开发者_如何学Goct sender, KeyEventArgs e)
{
if (e.Key.ToString() == "Escape")
{
string uri = "/Views/Music/ArtistbyAlbum";
this.NavigationService.Navigate(new Uri(uri, UriKind.Relative));
}
}
void LayoutRoot_KeyDown(object sender, KeyEventArgs e)
{
MessageBox.Show("hi");
}
Please help.
Thanks, Subhen
Unless you give focus to a control within the page you cannot get key events, that is essentially what having the focus means. The control that has focus is the control which will receive key events.
In the code behind on the page use the OnNavigatedTo event and call the Focus
method on the first control that can receive the focus (that is the first control that is visible, enabled and has IsTabStop
value of true).
Another approach might be to set the page IsTabStop
to true and call Focus
on the Page itself.
精彩评论