Wednesday, August 25, 2010

Use ComboBox in DataForm with DataServices in Silverlight 4

I have this scenario when I want to show user object in DataForm, in this user there is one ComboBox which show UserType. 

image

this is the Table Structure, which show the connection between PP_User and DD_UserType.
The final result is going to be like this:
image

Here is the XAML code:
image

Note: you can replace RadComboBox with normal ComboBox.

Create the Converter:
image

Method to GetUsers and Fill the DataForm with the result from this GetUsers
image

then GetUserType Method to get UserType data and fill it into combobox:
image

That’s it you’re done. Hope this help, this is my first attempt to write :) just email me if something not clear: at jlukmanh at yahoo dot com

Thursday, August 12, 2010

Utilize new Silverlight 4 TextInput Event.

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;

}

}