public MainViewerViewModel(MainViewer viewer) { // Add starting area to the list of favorites Favorites = new ObservableCollection <AreaViewModel>(); var startingAreaVm = new AreaViewModel(StartingArea.Clone(), this); Favorites.Add(startingAreaVm); startingAreaVm.NotifyAllPropertiesChanged(); // Create remaining parts of view model AddToFavoritesCommand = new AddToFavoritesCommand(this); UpdateFavoriteCommand = new UpdateFavoriteCommand(this); RerenderImageCommand = new RerenderImageCommand(this); SaveFavoritesCommand = new SaveFavoritesCommand(this); // EVIP: ICommand which needs an Action<> to be set, so it can use it during its execution. // Note: We need to provide the method to add an Area to the favorites list. // Example for providing an action (to invoke for all loaded elements) as a constructor parameter // of type Action<Area>. AddFavoritesFromFileCommand = new AddFavoritesFromFileCommand(this, AddToFavoritesCommand.Add); // EVIP: Cloning to avoid manipulation of // the same instance from many points. CurrentArea = StartingArea.Clone(); // Note: After cloning, we need to subscribe to the event of the new instance. CurrentArea.PropertyChanged += CurrentArea_PropertyChanged; }
public void Add(Area area) { var newAreaVM = new AreaViewModel(area, vm); vm.Favorites.Add(newAreaVM); // Now we need to notify the UI about the new values. newAreaVM.NotifyAllPropertiesChanged(); }
// Parameter: currently selected favorite (vm) public async override void Execute(object parameter) { // Update the currently selected favorite based on the current // zoom window. AreaViewModel selectedVM = (AreaViewModel)parameter; if (selectedVM != null) { selectedVM.UpdateModel(vm.CurrentArea); } else { var m = new Windows.UI.Popups.MessageDialog("Select the favorite to update first..."); await m.ShowAsync(); } }