Keyboard.KeyDown 연결된 이벤트

정의

키보드의 키를 누를 때 발생합니다.

see AddKeyDownHandler, and RemoveKeyDownHandler
see AddKeyDownHandler, and RemoveKeyDownHandler
see AddKeyDownHandler, and RemoveKeyDownHandler

예제

다음 예제에서는 이벤트에 대 KeyDown 한 이벤트 처리기를 연결 하는 만듭니다TextBox. Return 을 누르면 이벤트 처리기에서 TextBoxTextBlock텍스트를 표시 합니다.

<StackPanel>
  <TextBlock Width="300" Height="20">
    Type some text into the TextBox and press the Enter key.
  </TextBlock>
  <TextBox Width="300" Height="30" Name="textBox1"
           KeyDown="OnKeyDownHandler"/>
  <TextBlock Width="300" Height="100" Name="textBlock1"/>
</StackPanel>
private void OnKeyDownHandler(object sender, KeyEventArgs e)
{
    if (e.Key == Key.Return)
    {
        textBlock1.Text = "You Entered: " + textBox1.Text;
    }
}
Private Sub OnKeyDownHandler(ByVal sender As Object, ByVal e As KeyEventArgs)
    If (e.Key = Key.Return) Then
        textBlock1.Text = "You Entered: " + textBox1.Text
    End If
End Sub

설명

연결된 이벤트입니다. WPF는 연결된 이벤트를 라우트된 이벤트로 구현합니다. 연결된 이벤트는 기본적으로 해당 이벤트를 정의하지 않는 개체에서 처리할 수 있는 이벤트를 참조하기 위한 XAML 언어 개념이며, WPF는 이벤트가 경로를 트래버스할 수 있도록 하여 확장됩니다. 연결된 이벤트에는 코드에 직접 처리 구문이 없습니다. 코드에서 라우트된 이벤트에 대한 처리기를 연결하려면 지정된 Add*Handler 메서드를 사용합니다. 자세한 내용은 연결된 이벤트 개요를 참조하세요.

라우트된 이벤트 정보

Item 가치
식별자 필드 KeyDownEvent
라우팅 전략 버블링
대리인 KeyEventHandler

적용 대상

추가 정보