Silverlight键盘路由事件的详细概念将会在文章中为大家呈现。希望大家可以根据本文介绍内容在实际中操练以便,以加深我们对其的理解程度,并且在一定程度上提高我们对Silverlight开发工具的熟练使用。#t#
键盘事件KeyDown和KeyUp都支持路由事件
注意:当焦点在按钮上时,按Enter键好像不会路由事件,什么原因呢???
Silverlight键盘路由事件前台代码:
- < Canvas x:Name="LayoutRoot" Background=
"#46461F" KeyUp="LayoutRoot_KeyUp"> - < TextBox x:Name="textbox"
Width="200" Height="40" - Canvas.Top="80" Canvas.Left="80"/>
- < Button x:Name="button"
Width="100" Height="40" - Canvas.Top="80" Canvas.Left="280"
- Background="Red" Margin="20 0 0 0"
Content="Submit"/> - < TextBlock x:Name="Status"
Foreground="White" Text="Status" - Canvas.Left="80" Canvas.Top="200"/>
- < /Canvas>
Silverlight键盘路由事件后台代码:
- protected void LayoutRoot_KeyUp
(object sender, KeyEventArgs e)- {
- if (e.Key != Key.Unknown)
- {
- String msg = "The key " + e.Key.ToString();
- msg += " was pressed while focus was on "
+ (e.OriginalSource as FrameworkElement).Name;- Status.Text = msg;
- }
- }
Silverlight键盘路由事件的详细代码操作如上所示。