Skip to content

Instantly share code, notes, and snippets.

@atzimler
Created March 1, 2019 00:00
Show Gist options
  • Save atzimler/c16993a814f75cafba3dca9b54ca0ec5 to your computer and use it in GitHub Desktop.
Save atzimler/c16993a814f75cafba3dca9b54ca0ec5 to your computer and use it in GitHub Desktop.
ObservableCollection Example 2
public void ItemsToBeAddedAreRejectedCorrectlyWhileSomeoneElseIsListening()
{
var observableCollection = new ObservableCollection<int>();
observableCollection.CollectionChanged += (o, e) =>
{
if (e.Action == NotifyCollectionChangedAction.Add)
{
observableCollection.Clear();
}
};
observableCollection.CollectionChanged += (o, e) =>
{
// Do nothing on purpose.
};
observableCollection.Add(13);
observableCollection.Count.Should().Be(0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment