I'm trying to bind some CheckBoxes in a LongListSelector. They bind, and the correct CheckBoxes are checked/unchecked when the view is rendered, but I am unable to modify my underlying object by checking/unchecking the CheckBoxes.
<Grid Grid.Row="3">
<phone:LongListSelector ItemsSource="{Binding PlaceOfInterestCategories}">
<phone:LongListSelector.ItemTemplate>
<DataTemplate>
<CheckBox IsChecked="{Binding IsSelected, Mode=TwoWay}" Content="{Binding Name}"/>
</DataTemplate>
</phone:LongListSelector.ItemTemplate>
</phone:LongListSelector>
My ViewModel has the following code in it:
private ObservableCollection<PlaceOfInterestCategory> _placeOfInterestCategories;
public ObservableCollection<PlaceOfInterestCategory> PlaceOfInterestCategories
{
get { return _placeOfInterestCategories; }
set
{
if (_placeOfInterestCategories != value)
{
_placeOfInterestCategories = value;
OnPropertyChanged();
}
}
}
public event PropertyChangedEventHandler PropertyChanged;
[NotifyPropertyChangedInvocator]
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
var handler = PropertyChanged;
if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
}
-
[DataContract]
public class PlaceOfInterestCategory
{
[DataMember]
public int Id { get; set; }
[DataMember]
public string Name { get; set; }
[DataMember]
public bool IsSelected { get; set; }
}
I've tried to subscribe to the CollectionChanged event, but it's not being fired.
I could always handle Checked and Unchecked in my codebehind, but I'd rather not, and handle everything in my viewmodel.
I'd greatly appreciate any input as to how I can get the binding working properly.