/** cont */ private void OnDelete() { int toBeDeleted = BackOps.IndexOf(selectedBackup_); bool cd = CanDelete(); if (cd) { BackOps.Remove(selectedBackup_); } if (BackOps.Count > 0) { selectedBackup_ = BackOps.ElementAt((toBeDeleted == 0) ? 0 : (toBeDeleted - 1)); } }
/// <summary> /// Sets relay commands ( Relay commands provide communication between UI events and ViewModels ) /// </summary> private void InitRelayCommands() { // On Delete Backup Operation command, do the following : DeleteCommand = new RelayCommand(OnDelete, CanDelete); // On Add new Backup Operation command, do the following : AddCommand = new RelayCommand(() => { var newBackOp = new BackupOperation() { Alias = "New Backup Operation" }; DestinationInfo di = new DestinationInfo() { Path = new SilentBackupService.Path() { AbsolutePath = "enter path here..." } }; newBackOp.Destinations.Add(di); BackOps.Add(newBackOp); // DestInfos.Add(di); }, () => { return(true); }); // On Add new Backup Destinaion command, do the following : AddDestinationCommand = new RelayCommand(() => { DestinationInfo di = new DestinationInfo() { Path = new SilentBackupService.Path() { AbsolutePath = "enter path here..." } }; SelectedBackOp.Destinations.Add(di); DestInfos.Add(di); }, () => { return(SelectedBackOp != null); }); // On Toggle Enables/Disabled command, do the following : SwitchEnabledCommand = new RelayCommand(() => { SelectedBackOp.Enabled = !SelectedBackOp.Enabled; }, () => { return(SelectedBackOp != null); }); }
/// <summary> /// Sets relay commands ( Relay commands provide communication between UI events and ViewModels ) /// </summary> public void InitRelayCommands() { //BackOps.CollectionChanged += UpdateBackupListUI; // On Delete Backup Operation command, do the following : DeleteCommand = new RelayCommand(() => { int toBeDeleted = BackOps.IndexOf(SelectedBackup); BackOps.Remove(SelectedBackup); if (BackOps.Count > 0) { SelectedBackup = BackOps.ElementAt((toBeDeleted == 0) ? 0 : (toBeDeleted - 1)); } else { SelectedBackup = null; } SaveConfiguration(); RaisePropertyChanged("BackOps"); }, () => { return(selectedBackup_ != null); }); // On Add new Backup Operation command, do the following : AddCommand = new RelayCommand(() => { var newId = BackOps?.Count > 0 ? BackOps.Max(x => x.Id) + 1 : 1; var newBackOp = new BackupOperation() { Alias = "New Backup", Id = newId, Enabled = true }; newBackOp.Source.AbsolutePath = MainWindow.PathPlaceholder.Replace("path", "source"); BackOps.Add(newBackOp); SelectedBackup = newBackOp; }, () => { //return BackOps.LastOrDefault() != null ? BackOps.LastOrDefault().IsValid : false; return(true); }); // On Add new Backup Destinaion command, do the following : AddDestinationCommand = new RelayCommand(() => { DestinationInfo di = new DestinationInfo() { Path = new SilentBackupService.Path() { AbsolutePath = MainWindow.PathPlaceholder.Replace("path", "destination") } }; SelectedBackup.Destinations.Add(di); DestInfos.Add(di); }, () => { return(SelectedBackup != null); }); // On Toggle Enables/Disabled command, do the following : SwitchEnabledCommand = new RelayCommand(() => { SelectedBackup.Enabled = !SelectedBackup.Enabled; }, () => { return(SelectedBackup != null); }); SaveCommand = new RelayCommand(() => { configuration_.BackupOperations = BackOps; SaveConfiguration(); RaisePropertyChanged("BackOps"); }, () => { return(true); }); DiscardCommand = new RelayCommand <BackupOperation>((rollback) => { if (rollback != null) { var backup = BackOps.SingleOrDefault(x => x.Id == rollback.Id); BackOps.Insert(BackOps.IndexOf(backup), rollback); BackOps.Remove(backup); SelectedBackup = rollback; } else { if (DeleteCommand.CanExecute(null)) { DeleteCommand.Execute(null); } } }, (rollback) => { return(true); }); }