Saturday, May 29, 2010

Silverlight 4.0 <=WPF --ICommand

Now Silverlight 4.0 Supports ICommand  Interface but not fully only two controls

  1. Button
  2. Hyperlink button.

In Silverlight 4.0 the Button UI Element has to extra properties Command and CommandParamter.

 image

Here i am going to show simple example using ICommand Interface in Silverlight 4.0.

First create a Silverlight application. 

image

Now we need to Add Class file to the project and Implement the ICommand Interface.

image

 

Here the above code we are checking if user did not enter anything in textbox we are not executing the command . If He /She enters something and click button we will display the Entered Text in MessageBox.

Now lets Add XAML code to create Simple UI .  Here i am adding one Textbox and Button.

image

Now lets do the Binding (wire up) our Command class to this UI.  Here i am doing Element to Element data binding.

image

Note:

I do not have any code in CodeBehind in MainPage.Xmal.cs for the Button Click.

image

Now run the application and click Execute Command Button and see what is happening after that put some text in text box and click it now the message box displayed the text which you entered.

image

Nandri(Thanks)

SreenviasaRagavan.

No comments: