I use VS2010, C# to develop Silverlight 4 app, I use following code in my XAML file:
<Canvas x:Name="Scene" FlowDirection="LeftToRight" Background="White" KeyDown="Scene_KeyDown" MouseMove="Scene_MouseMove">
and this is my XAML.cs file, I want to display a message box if any key is pressed (it is for test only):
private void Scene_KeyDown(object sender, KeyEventArgs e)
{
MessageBox.Show("1");
}
But nothing is displayed after keys are pressed! What is going wrong? Should I set any property? command? tabstop? keypreview?
Looks like this answer will solve your problem:
You need to have at least something inside the Canvas that can receive focus, and you will find that the event will bubble up.