Consider the following code:
public ObservableCollection<Message> Messages {
get { return new ObservableCollection<Message>(); }
}
Is there anything I can do to prevent the caller code from adding/removing/changing items?
EDIT: Sorry, everyone, I just noticed it’s a dupe, but the accepted answer is wrong.
What about using ReadOnlyObservableCollection
Code would be:
Having read aboutReadOnlyObservableCollection Anti Pattern I realise the above is the not a good approach and may lead to subtle bugs. The suggested approach is: