Recommended

Skip Navigation LinksHome / News / View News

Handling DataGrid.SelectedItems in an MVVM-friendly manner

+ Add to SilverlightShow Favorites
0 comments   /   posted by Silverlight Show on May 20, 2010
(0 votes)
If you are wondering if there is an MVVM-friendly way to get a DataGrid’s SelectedItems into the ViewModel, read this blog post of Laurent Bugnion and find out the answer.

The issue there is as old as the DataGrid (that’s not very old but still): SelectedItem (singular) is a DependencyProperty and can be databound to a property in the ViewModel. SelectedItems (plural) is not a DependencyProperty.

Thankfully the answer is very simple: Use EventToCommand to call a Command in the ViewModel, and pass the SelectedItems collection as parameter.

Share


Comments

Comments RSS RSS
No comments

Add Comment

 
 

   
  
  
   
Please add 7 and 7 and type the answer here:

Help us make SilverlightShow even better. Whether you'd like to suggest a change in the structure, content organization, section layout or any other aspect of SilverlightShow appearance - we'd love to hear from you! Need material (article, tutorial, or other) on a specific topic? Let us know and SilverlightShow content authors will work to have that prepared for you. (hide this)