CheckBox in ListView with MVVM, notify changes

ChrisDrewChrisDrew GBMember ✭✭
edited January 13 in Xamarin.Forms

I am using the MVVM model and have a listview which displays a series of checkboxes. My xaml is

<CheckBox Grid.Row="0" Grid.Column="1" Color="{Binding BreakfastStatusColour}" IsChecked="{Binding BreakfastClaimed, Mode=TwoWay}" HorizontalOptions="Center" CheckedChanged="CheckBox_CheckedChanged"  />

My issue is that when the user checks or unchecks the check box I need the colour to potentially change. My listview has an observablecollection as it's data source and as expected this is being updated as the user checks a box. However I'm not sure how I can inform the UI that the colour also needs to be updated. Obviously if this was a locally bound field I could use 'NotifyPropertyChanged' but the field being updated is in a collection...

I did try capturing the CheckedChanged event but I have the same issue of how to notify to get the colour change to be recognised?

Best Answer


  • jhershmanjhershman Member ✭✭

    I did a similiar thing triggered by the user selecting the item in the ListBox. Described here: Xamarin Forms: Set Background Color of Item Selected in ListView from ViewModel

  • ChrisDrewChrisDrew GBMember ✭✭

    This link comes back to this article - could you please re-post as I am struggling to find the article...

  • jhershmanjhershman Member ✭✭

    I guess I am not allowed to actually post a link because I am new -
    " -- "

  • ChrisDrewChrisDrew GBMember ✭✭

    Thanks I was also missing the fact that the object I was using to hold the settings was not an observable object - it was in an observablecollection but that wasn't enough as I couldn't call 'NotifyPropertyChanged'. Changed the object base type and set the code as suggested and it's working great - my thanks.

Sign In or Register to comment.