/// <summary> /// Construct a ShellViewModel. /// </summary> /// public ShellViewModel(IDataSourceManager DataSourceManager, IDialogService DialogService) { _contactsFilePath = $"{ Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) }\\Contacts.xml"; _dataSourceManager = DataSourceManager; _dialogService = DialogService; Contacts = new BindableCollection <Contact>(_dataSourceManager.LoadContactsFromFile(_contactsFilePath)); SaveConfirmationDialogCommand = new RelayCommand(Save); CancelConfirmationDialogCommand = new RelayCommand(Cancel); }
/// <summary> /// Open cancelling dialog and load contacts in case of "Yes" or do nothing in case of "No". /// </summary> /// <param name="parameter">Specify the owner of cancelling dialog</param> public void Cancel(object parameter) { DialogViewModelBase dialogViewModel = new DialogYesNoViewModel("Cancel changes", $"Are you sure you want to cancel your changes and load contacts from file: { _contactsFilePath }?"); if (_dialogService.OpenDialog(dialogViewModel, parameter as Window) == DialogResult.Yes) { Contacts = new BindableCollection <Contact>(_dataSourceManager.LoadContactsFromFile(_contactsFilePath)); SavingActive = false; CancellingActive = false; } }