=======================前台=====================
<UserControl x:Class="SilverlightApplication10.keyevent"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="400" Height="300">
<Canvas x:Name="LayoutRoot" Background="greenyellow">
<TextBlock Height="33" Width="137" Canvas.Left="8" Canvas.Top="8" Text="键盘事件" TextWrapping="Wrap" FontSize="26.667"/>
<TextBlock Height="41" Width="82" Canvas.Left="10" Canvas.Top="47" Text="输入" TextWrapping="Wrap" FontSize="18.667"/>
<TextBox x:Name="txt1" Canvas.Left="67" Canvas.Top="47" Text="" TextWrapping="Wrap" Width="265"/>
<TextBlock Height="41" Width="82" Canvas.Left="10" Canvas.Top="88" Text="显示" TextWrapping="Wrap" FontSize="18.667"/>
<ScrollViewer Height="100" Width="265" Canvas.Left="67" Canvas.Top="92">
<TextBlock x:Name="txtbck1" Height="100" Width="265" Text="" TextWrapping="Wrap"/>
</ScrollViewer>
<TextBlock Height="19" Width="172" Canvas.Left="34" Canvas.Top="236" Text="按DELETE或退格键清除" TextWrapping="Wrap"/>
</Canvas>
</UserControl>
==========================后台=======================
Partial Public Class keyevent
Inherits UserControl
Public Sub New
InitializeComponent()
End Sub
Private Sub keyevent_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Input.KeyEventArgs) Handles Me.KeyUp
Me.txtbck1.Text += e.Key.ToString
End Sub
Private Sub txt1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Input.KeyEventArgs) Handles txt1.KeyUp
If e.Key = Key.Delete Or e.Key = Key.Back Then
Me.txtbck1.Text = ""
End If
End Sub
End Class