Condividi tramite


UIElement.TextInput Event

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

Occurs when a UI element gets text in a device-independent manner.

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

Syntax

'Declaration
Public Event TextInput As TextCompositionEventHandler
public event TextCompositionEventHandler TextInput
<uiElement TextInput="eventhandler"/>

Remarks

This event is raised asynchronously.

Use a handler based on TextCompositionEventHandler to handle this event.

TextInput is generally only raised by elements that are already handling for key input on a per-key basis using KeyUp or KeyDown and coalescing the results, such as TextBox. TextInput is an event that is general to UIElement rather than specific to TextBox because it is a routed event that bubbles, and thus can potentially be handled by a compositing container. For example, a custom control might be interested in updates to one or more of its text box components, and might hook up TextInput at the component root level as one of the operations in its OnApplyTemplate implementation.

The TextInput event allows a component or application to listen for text input in a device-independent manner. The keyboard is the primary means of text input, but potentially custom touch gestures and other input techniques including an input method editor (IME) can also raise TextInput.

Because of key combinations—either in default keyboards or through input method editors—multiple key events might raise just one text input event.

This event is a bubbling event. This means that if multiple TextInput handlers are registered for a sequence of objects connected by parent-child relationships in the object tree, the event is received by each object in that relationship, with the route going in the parent direction. The sender available to the event handler identifies the object where the event is handled, not necessarily the object that actually received the input condition that initiated the event. To get the object that initiated the event, use the OriginalSource value of the event's RoutedEventArgs event data. For more information on routed event concepts, see Events Overview for Silverlight.

IME support in Silverlight also includes attached properties that can influence IME handling and behavior, which can be set on a TextBox. See InputMethod.

TextInput and OnTextInput

For control classes (anything that derives from Control) there is potentially an assigned virtual/override handler for text input, as defined by OnTextInput.

Version Information

Silverlight

Supported in: 5, 4

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1

Platforms

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