1.インターフェイスデザイン
インタフェースコード:
<グリッド> <Grid.RowDefinitions> <RowDefinition高さ= " オート" > </ RowDefinition> <RowDefinition高さ= " * " > </ RowDefinition> <RowDefinition高さ= " オート" > </ RowDefinition> </Grid.RowDefinitions> <DockPanel Grid.Row = " 0 " > <TextBlockの>ここに入力します。</ TextBlockの> <= TextBoxのFocusableの" 真の"幅= "710 " PreviewKeyDown = " PKeyUpAndDown" PreviewKeyUp = " PKeyUpAndDown "のKeyDown = " PKeyUpAndDown " keyUpイベント= " PKeyUpAndDown " PreviewTextInput = " PTextInput "のTextInput = " PTextInput " > </テキストボックス> </ DockPanel> <リストボックスGrid.Row = " 1 "証拠金= " 10,10 、10,44 "名前= " MyListBoxという" > </ ListBoxコントロール> <ボタンをクリックして= "Button_Click_2 " Grid.Row = " 2"たHorizontalAlignment = " 右"幅= " 60 "証拠金= " 0,0,20,30 " >明確な</ボタン> </グリッド>
イベントコード:
プライベート 無効 Button_Click_2(オブジェクト送信者、RoutedEventArgs e)の { この.mylistbox.Items.Clear(); } プライベート ボイド PKeyUpAndDown(オブジェクト送信者、KeyEventArgs E) { 文字列メッセージ= " イベント:" + e.RoutedEvent + " " + " キー:" + e.Key。 この.mylistbox.Items.Add(メッセージ)。 } プライベート ボイド PTextInput(オブジェクトメッセージ=送信者、TextCompositionEventArgs E) { 文字列" イベント:" + e.RoutedEvent + " " + " キー:" + e.Text。 この.mylistbox.Items.Add(メッセージ)。 }
レンダリング: