I have a ListView whose ItemSource is an ObservableCollection of Message objects. Message objects implement INotifyPropertyChanged.
I am changing properties on a message object in the ObservableCollection but it isn't updating my UI (which is a custom rendered cell) until I scroll the list to hide, then show the updated item.
` public class Message :INotifyPropertyChanged
{
public Message ()
{
}
public event PropertyChangedEventHandler PropertyChanged;
public string subject { get; set; }
public bool sent { get; set; }
public void SetSent(bool value) {
sent = value;
Device.BeginInvokeOnMainThread (() => {
OnPropertyChanged ("sent");
});
}
protected void OnPropertyChanged(string name)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(name));
}
}
}`
This updates the ui:
messages_ = new ObservableCollection<Message> ();
messages_.Add(messageA);
messages_.Remove(messageB)
This Doesn't:
foreach(Message m in messages_) {
m.SetSent(false);
}
Can anyone tell me why the UI doesn't update?
Furthermore the messages will eventually be grouped and the ItemSource changed to
messages_ = new ObservableCollection<GroupedMessage> ();
public class GroupedMessage : ObservableCollection<Message>
{
public string date { get; set; }
}
Do I need to add INotifyPropertyChanged to the GroupedMessage class?
Thanks in advance