你这样做:
// get some Message from OC<Message> collection Message
var message = Messages.First();
message.Answers.Add(new CAnswer { Text = "HURRDURR" }); // add an answer
但是您的 CMessage 只会在您执行此操作时调用 RaisePropertyChanged
var message = Messages.First();
var answers = new ObservableCollection<CAnswer>();
answers.Add(new CAnswer { Text = "LOL" });
message.Answers = answers; // triggers here
第一个引发 Answers 集合的 CollectionChanged 事件。第二个更改将导致您的set
方法触发的 Answers 集合,从而引发 CMessage 类的 PropertyChanged 事件。
BTW, you're doing this wrong. You shouldn't let people set your collection property. It isn't a best practice, allows the property to be set to null (which is bad), etc. You should only have read-only property collections. If users are interested in the property changing they should subscribe to the CollectionChanged event of your property.