Exemplo n.º 1
0
        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;
            }
        }
Exemplo n.º 2
0
        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();
        }
Exemplo n.º 3
0
        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;
                }
            }
        }
Exemplo n.º 4
0
 private bool CanExecuteDelete(PersonItem input)
 {
     return(input != null);
 }
Exemplo n.º 5
0
 private bool CanExecuteAdd(PersonItem input)
 {
     return(!string.IsNullOrWhiteSpace(input.Name) &&
            !string.IsNullOrWhiteSpace(input.Email));
 }