Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

TextBoxBase.TextChanged Event

Occurs when content changes in the text element.

Namespace: System.Windows.Controls.Primitives
Assembly: PresentationFramework (in presentationframework.dll)
XML Namespace:  http://schemas.microsoft.com/winfx/2006/xaml/presentation

public event TextChangedEventHandler TextChanged
/** @event */
public void add_TextChanged (TextChangedEventHandler value)

/** @event */
public void remove_TextChanged (TextChangedEventHandler value)

In JScript, you can handle the events defined by a class, but you cannot define your own.
<object TextChanged="TextChangedEventHandler" .../>

Identifier Field

TextChangedEvent

Routing Strategy

Bubbling

Delegate

RoutedEventHandler

For a TextBox, this event occurs when its text changes, for a RichTextBox, this event occurs when any content or formatting changes (i.e. images, table, background color, etc).

This example shows one way to use the TextChanged event to execute a method whenever the text in a TextBox control has changed.

In the code-behind class for the XAML that contains the TextBox control that you want to monitor for changes, insert a method to call whenever the TextChanged event fires. This method must have a signature that matches what is expected by the TextChangedEventHandler delegate.

The event handler is called whenever the contents of the TextBox control are changed, either by a user or programmatically.

Note: This event fires when the TextBox control is created and initially populated with text.

In the Extensible Application Markup Language (XAML) that defines your TextBox control, specify the TextChanged attribute with a value that matches the event handler method name.

<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>

In the code-behind class for the XAML that contains the TextBox control that you want to monitor for changes, insert a method to call whenever the TextChanged event fires. This method must have a signature that matches what is expected by the TextChangedEventHandler delegate.

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

The event handler is called whenever the contents of the TextBox control are changed, either by a user or programmatically.

Note: This event fires when the TextBox control is created and initially populated with text.

Comments

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0

Community Additions

Show:
© 2014 Microsoft