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

10 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. 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
  5. I used to be able to find good info from your content.


    my site - book of raw kostenlos spielen

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

    ReplyDelete
  7. Hello! Someone in my Facebook group shared this website with us, so I came to give it a look. I’m enjoying the information. I’m bookmarking and will be tweeting this to my followers! Wonderful blog and amazing design and style.
    python training Course in chennai
    python training in Bangalore
    Python training institute in bangalore

    ReplyDelete
  8. I Regreat For Sharing The information The InFormation shared Is Very Valuable Please Keep Updating Us Time Just Went On Reading The Article Python Online Training AWS Online Training Hadoop Online Training Data Science Online Training

    ReplyDelete
  9. Wow ! what an interesting blog.Thanks for sharing your informative post on development.Your work is very good and I appreciate you and hoping for some more informational posts.keep writing and sharing.
    Salesforce Training in Chennai

    Salesforce Online Training in Chennai

    Salesforce Training in Bangalore

    Salesforce Training in Hyderabad

    Salesforce training in ameerpet

    Salesforce Training in Pune

    Salesforce Online Training

    Salesforce Training

    ReplyDelete