public async void Add(PersonItem input) { try { this.IsIdle = false; if (input.Name == @"a") { await this.Dialog.DisplayAsync(@"Cannot insert person with this 'reserved' name."); return; } this.Items.Add(new PersonItem { Name = input.Name, Email = input.Email }); this.NewItem.Name = string.Empty; this.NewItem.Email = string.Empty; } finally { this.IsIdle = true; } }
public PersonItemViewModel(IDialogInterface dialog) { if (dialog == null) { throw new ArgumentNullException("dialog"); } this.Dialog = dialog; this.Items = new ObservableCollection <PersonItem>(); this.AddCommand = new DelegateCommand <PersonItem>(this.Add, this.CanExecuteAdd); this.DeleteCommand = new DelegateCommand <PersonItem>(this.Delete, this.CanExecuteDelete); this.NewItem = new PersonItem(); this.NewItem.PropertyChanged += (sender, args) => this.AddCommand.RaiseCanExecuteChanged(); }
private async void Delete(PersonItem input) { var confirmed = await this.Dialog.ConfirmAsync(@"Are you sure you want to delete this item?") ?? false; if (confirmed) { try { this.IsIdle = false; await Task.Delay(TimeSpan.FromSeconds(3)); this.Items.Remove(input); } finally { this.IsIdle = true; } } }
private bool CanExecuteDelete(PersonItem input) { return(input != null); }
private bool CanExecuteAdd(PersonItem input) { return(!string.IsNullOrWhiteSpace(input.Name) && !string.IsNullOrWhiteSpace(input.Email)); }