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
245
MVVM Binding to IsSelected
posted

I'd like to bind xamDataGrid rows to an IsSelected property in my ViewModel, so I did this:

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

        <EventSetter Event="MouseLeftButtonUp" Handler="object_MouseLeftClick"/>
        <EventSetter Event="MouseDoubleClick" Handler="object_MouseDoubleClick"/>
        <EventSetter Event="MouseRightButtonUp" Handler="object_MouseRightClick"/>
        <Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}"/>

    </Style>

However, this seems to have no effect because the IsSelected property of DataRecordPresenter seems to remain false when a row is selected! For instance, when I set a breakpoint in object_MouseDoubleClick, ((DataRecordPresenter)sender).IsSelected==false even though the row is clearly selected. So how do I do it properly?
Note: I need two-way binding, so that items can be selected or deselected by changing the ViewModel.IsSelected property. I have learned that this can be tricky even with a standard ListBox or ListView control.

Parents
No Data
Reply
  • 138253
    Offline posted

    Hello,

     

    Thank you for your post. I have been looking through it and I can say that if you didn’t set the XamDataGrid’s FieldSettings’ CellClickAction Property, its default value is EnterEditModeIfAllowed, which means that the Record is only selected if you click the RecordSelector at the beginning of the Row. If you then click at the Record itself, it becomes Unselected again. Please let me know if need further clarifications on this matter.

     

    Looking forward for your reply.

Children