Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
180
MVVM - Binding multiple selections to your view model
posted

The new xamDataGrid supports IsSynchronizedWithCurrentItem, but I didn't have a way to communicate multiple selections to my view model.

After piecing several forum posts together, I came up with this:

- Add an IsSelected property to your item view model:

 

public bool IsSelected { get; set; }

- Bind the DataRecordPresenter's IsSelected to your property:

<igDP:XamDataGrid.Resources>

<Style TargetType="{x:Type igDP:DataRecordPresenter}">

<Setter Property="IsSelected" Value="{Binding DataItem.IsSelected, Mode=TwoWay}"/>

</Style>

</igDP:XamDataGrid.Resources>

Now you can check your view models to see which ones are selected.

  • 2116
    Offline posted

    This doesn't seem very reliable because when you scroll the grid the records seem to lose their selected property.

  • 155
    posted

    Hi

     

    Very new to binding and MVVM. can you please explain how to check to view model (datacontext) for the selected records?

     

    Nick