New TextInput event in Silverlight 4 is pretty useful when it comes to handle key event in the textbox input. Along with TextInputStart and TextInputUpdate these 3 new events will be very useful in handling the keystrokes validation in keyboard input.
I found the most important from these 3 new event is the TextInput event handling by itself. By only using TextInput by itself we can provide the good mechanism for the use to enter or update the text into the textbox. Unlike the Keyboard event for example KeyDown or KeyUp event which has KeyEventArgs, this TextInput event has TextCompositionEventArgs.
This TextInput event only has 3 types of triggered which are:
- By the Return/Enter key stroke.
- By the Escape key stroke.
- By the Backspace stroke (backspacing until the textbox/any input object empty)
We can check or validate the type of triggered which activate this TextInput event by comparing the TextInput.Text with string value.
Those string value are:
- Return/Enter key stroke = "/r"
- Backspace key stroke = "/b"
- Escape key stroke is the symbol which I can't translate it to the string value. (please let me know)
To put it in code we can simply say:
void txtNameUpdate_TextInput(object sender, TextCompositionEventArgs e)
{
switch (e.Text)
{
case
"\r":
//User hit enter button do something.
break;
case
"\b":
//User hit backspace multiple times until input object empty, do something here..
break;
default:
//User hit escape button, do something here..
break;
}
}

No comments:
Post a Comment