次の方法で共有


TextBox.TextChanged Event

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Occurs when content changes in the text box.

Namespace:  System.Windows.Controls
Assembly:  System.Windows (in System.Windows.dll)

Syntax

'Declaration
Public Event TextChanged As TextChangedEventHandler
public event TextChangedEventHandler TextChanged
<TextBox TextChanged="eventhandler"/>

Remarks

User input or setting the Text property to a new value raises the TextChanged event.

If the Text property is set to the same string as the content in the TextBox, the event is not raised.

The TextChanged event is asynchronous. The event cannot be canceled.

NoteNote:

If the text and the selection is changed in a TextBox, the TextChanged event is raised before the SelectionChanged event.

Examples

The following code snippets display a read-write text box and a read-only text box. As you type text in the read-write text box, the text is displayed in the read-only text box. This example is part of a larger example available in the TextBox class overview.

<TextBlock Margin="20,20,0,0" Text="Type Text Here"/>

<TextBox x:Name="ReadWriteTB" TextChanged="ReadWriteTB_TextChanged"  IsReadOnly="False" HorizontalAlignment="Left" Margin="20,5,0,0" Height="35" Width="200" />

<TextBlock Margin="20,20,0,0" Text="Read Only TextBox"/>

<TextBox x:Name="ReadOnlyTB"  IsReadOnly="True" HorizontalAlignment="Left" Margin="20,5,0,0" Height="35" Width="200" />
    'The following method displays the text entered in ReadWriteTB in ReadOnlyTB.
    Private Sub ReadWriteTB_TextChanged(ByVal sender As Object, ByVal e As RoutedEventArgs)
        ReadOnlyTB.Text = ReadWriteTB.Text
    End Sub


//The following method displays the text entered in ReadWriteTB in ReadOnlyTB.
private void ReadWriteTB_TextChanged(object sender, RoutedEventArgs e)
{
    ReadOnlyTB.Text = ReadWriteTB.Text;
}

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.