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
 {
    get
    {
      //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
     //
     //
}

7 comments:

  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.

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

    ReplyDelete
  3. Awesome post.

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

    ReplyDelete
  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

    ReplyDelete
  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

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


    my site - book of raw kostenlos spielen

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

    ReplyDelete

 

Sample text

Sample Text