public MoviePageViewModel() : base(new MovieCatalog()) { // Initialise the delete Command object with a source (the page view model itself), // a target (the aggregated Catalog), and a condition (an item must be selected) _deleteCommand = new DeleteCommandBase <Movie>(this, Catalog, () => ItemSelected != null); // Define how to react to changes in item selection ItemSelectionChanged += ItemSelectionChangedHandler; // Define how to react to changes in aggregated catalog Catalog.CatalogChanged += CatalogChangedHandler; }
public MovieCatalog() { // Add some domain objects directly to the Catalog Create(new Movie("Alien", 1979)); Create(new Movie("Terminator", 1984)); Create(new Movie("Inception", 2010)); Create(new Movie("Se7en", 1995)); Create(new Movie("Arrival", 2016)); // The Catalog also acts as a data wrapper, which is // why the first argument is also "this" _deleteCommand = new DeleteCommandBase <Movie>(this, this, () => _itemSelected != null); // When the Catalog content changes (i.e. when something is deleted, // call OnPropertyChanged for the All property, so those binding to // this property are notified of the change. CatalogChanged += i => OnPropertyChanged(nameof(All)); }