방법: TextBox에서 텍스트가 변경되는 시점 감지

이 예제에서는 TextChanged 이벤트를 사용하여 TextBox 컨트롤의 텍스트가 변경될 때마다 메서드를 실행하는 한 가지 방법을 보여 줍니다.

변경 내용을 모니터링하려는 TextBox 컨트롤이 포함된 XAML에 대한 코드 숨김 클래스에서 TextChanged 이벤트가 발생할 때마다 호출할 메서드를 삽입합니다. 이 메서드에는 TextChangedEventHandler 대리자가 예상한 것과 일치하는 서명이 있어야 합니다.

이벤트 처리기는 TextBox 컨트롤의 내용이 변경될 때마다 사용자에 의해 또는 프로그래밍 방식으로 호출됩니다.

참고

이 이벤트는 TextBox 컨트롤이 만들어지고 처음에 텍스트로 채워지면 발생합니다.

TextBox 컨트롤 정의

TextBox 컨트롤을 정의하는 XAML(Extensible Application Markup Language)에서 이벤트 처리기 메서드 이름과 일치하는 값으로 TextChanged 특성을 지정합니다.

<TextBox  TextChanged="textChangedEventHandler">
  Here is the initial text in my TextBox.  Each time the contents of this TextBox are changed, 
  the TextChanged event  fires and textChangedEventHandler is called.
</TextBox>

TextBox 컨트롤 변경 내용 모니터링

변경 내용을 모니터링하려는 TextBox 컨트롤이 포함된 XAML에 대한 코드 숨김 클래스에서 TextChanged 이벤트가 발생할 때마다 호출할 메서드를 삽입합니다. 이 메서드에는 TextChangedEventHandler 대리자가 예상한 것과 일치하는 서명이 있어야 합니다.

// TextChangedEventHandler delegate method.
private void textChangedEventHandler(object sender, TextChangedEventArgs args)
{
    // Omitted Code: Insert code that does something whenever
    // the text changes...
} // end textChangedEventHandler
' TextChangedEventHandler delegate method.
Private Sub textChangedEventHandler(ByVal sender As Object, ByVal args As TextChangedEventArgs)
    ' Omitted Code: Insert code that does something whenever
    ' the text changes...
End Sub

이벤트 처리기는 TextBox 컨트롤의 내용이 변경될 때마다 사용자에 의해 또는 프로그래밍 방식으로 호출됩니다.

참고

이 이벤트는 TextBox 컨트롤이 만들어지고 처음에 텍스트로 채워지면 발생합니다.

주석

참고 항목