Keyboard.GotKeyboardFocus 연결된 이벤트

정의

요소가 키보드 포커스를 받으면 발생합니다.

see AddGotKeyboardFocusHandler, and RemoveGotKeyboardFocusHandler
see AddGotKeyboardFocusHandler, and RemoveGotKeyboardFocusHandler
see AddGotKeyboardFocusHandler, and RemoveGotKeyboardFocusHandler

예제

다음 예에서는 TextBox 에 대 한 이벤트 처리기를 연결 합니다 GotKeyboardFocus 이벤트 및 LostKeyboardFocus 이벤트입니다. 경우는 TextBox 키보드 포커스를 배경 색이 변경 및 텍스트는 TextBox 지워집니다. 경우는 TextBlock 키보드 포커스를 잃을 배경색 변경 되 고 샘플에서 사용 되는 변수를 다시 설정 하는 메서드를 호출 합니다.

<Border BorderBrush="Black" BorderThickness="1"
        Width="200" Height="100" Margin="5">
  <StackPanel>
    <Label HorizontalAlignment="Center" Content="Type Text In This TextBox" />
    <TextBox Width="175"
             Height="50" 
             Margin="5"
             TextWrapping="Wrap"
             HorizontalAlignment="Center"
             VerticalScrollBarVisibility="Auto"
             GotKeyboardFocus="TextBoxGotKeyboardFocus"
             LostKeyboardFocus="TextBoxLostKeyboardFocus"
             KeyDown="SourceTextKeyDown"/>
  </StackPanel>
</Border>
private void TextBoxGotKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
{
    TextBox source = e.Source as TextBox;

    if (source != null)
    {
        // Change the TextBox color when it obtains focus.
        source.Background = Brushes.LightBlue;

        // Clear the TextBox.
        source.Clear();
    }
}
Private Sub TextBoxGotKeyboardFocus(ByVal sender As Object, ByVal e As KeyboardFocusChangedEventArgs)
    Dim source As TextBox = TryCast(e.Source, TextBox)

    If source IsNot Nothing Then
        ' Change the TextBox color when it obtains focus.
        source.Background = Brushes.LightBlue

        ' Clear the TextBox.
        source.Clear()
    End If
End Sub
private void TextBoxLostKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
{
    TextBox source = e.Source as TextBox;

    if (source != null)
    {
        // Change the TextBox color when it loses focus.
        source.Background = Brushes.White;

        // Set the  hit counter back to zero and updates the display.
        this.ResetCounter();
    }
}
Private Sub TextBoxLostKeyboardFocus(ByVal sender As Object, ByVal e As KeyboardFocusChangedEventArgs)
    Dim source As TextBox = TryCast(e.Source, TextBox)

    If source IsNot Nothing Then
        ' Change the TextBox color when it loses focus.
        source.Background = Brushes.White

        ' Set the  hit counter back to zero and updates the display.
        Me.ResetCounter()
    End If
End Sub

설명

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

키보드 포커스는 키보드 입력을 수신 하는 개체를 참조 합니다. 키보드 포커스가 있는 요소가 IsKeyboardFocusedtrue합니다. 전체 바탕 화면에 키보드 포커스가 있는 요소가 하나만 있을 수 있습니다. 논리 포커스는 포커스가 있는 포커스 범위 내에서 개체를 가리킵니다. 포커스, 키보드 포커스와 논리 포커스가에 대 한 자세한 내용은 참조 하세요. 입력 개요 하 고 포커스 개요합니다.

경우는 PreviewGotKeyboardFocus 이벤트 또는 PreviewLostKeyboardFocus 이벤트를 처리, 키보드 포커스는 변경 합니다.

라우팅 이벤트 정보

식별자 필드 GotKeyboardFocusEvent
라우팅 전략 버블링
대리자 KeyboardFocusChangedEventHandler

적용 대상