Social Icons

Wednesday, January 25, 2012

Handling Button Click Event in ViewModel using MVVM structure of Silverlight

1. Write Xaml as follows
<Button Command="{Binding SearchCommand}" Content="Search" 
Height="20" HorizontalAlignment="Right" 
Margin="0,16,19,0" TabIndex="14" VerticalAlignment="Top" 
Width="75" Grid.Column="2" />
2. Write in viewModel as follows
//This is command against when search button will be pressed
 public RelayCommand SearchCommand
      //GetDatais a method for your action on click event
      return new RelayCommand(GetData);
3. You Method for for on button click
protected void GetData()
     //Your work


  1. but in silverlight button click event, the attribute name "Command" was not present.. How to overcome that and i need to bind the selected value record in the Datagrid in Silverlight MVVM..
    Any help from ur side please.

    1. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a .Net developer learn from Dot Net Training in Chennai. or learn thru ASP.NET Essential Training Online . Nowadays Dot Net has tons of job opportunities on various vertical industry.
      or Javascript Training in Chennai. Nowadays JavaScript has tons of job opportunities on various vertical industry.

  2. You can user observeable collection for that purpose to bind the data with grid in silverlight

  3. Awesome post.

    Here is my page ... books of ra online spielen

  4. Thanks for sharing your info. I truly appreciate your efforts and I am waiting
    for your further write ups thank you once again.

    Here is my page: book of ra android boerse

  5. Hmm is anyone else having problems with the pictures on this
    blog loading? I'm trying to determine if its a problem on my end or if it's the blog.
    Any suggestions would be greatly appreciated.

    My blog post - book of ra kostenlos spielen ohne anmeldung

  6. I used to be able to find good info from your content.

    my site - book of raw kostenlos spielen

  7. This does not work for MvvmLight,the RelayCommand is different than that in MS Mvvm.



Sample text

Sample Text