コード例 #1
0
        async void OnDismiss(object sender, EventArgs e)
        {
            Button button = (Button)sender;

            button.IsEnabled = false;
            this.IsBusy      = true;
            try
            {
                string title  = titleCell.Text;
                string author = authorCell.Text;
                string genre  = genreCell.Text;

                if (string.IsNullOrWhiteSpace(title) ||
                    string.IsNullOrWhiteSpace(author) ||
                    string.IsNullOrWhiteSpace(genre))
                {
                    this.IsBusy = false;
                    await this.DisplayAlert("Missing Information",
                                            "You must enter values for the Title, Author, and Genre.",
                                            "OK");
                }
                else
                {
                    if (existingBook != null)
                    {
                        existingBook.Title      = title;
                        existingBook.Genre      = genre;
                        existingBook.Authors[0] = author;

                        await manager.UpdateAsync(existingBook);

                        int pos = books.IndexOf(existingBook);
                        books.RemoveAt(pos);
                        books.Insert(pos, existingBook);
                    }
                    else
                    {
                        Book book = await manager.AddAsync(title, author, genre);

                        books.Add(book);
                    }

                    await Navigation.PopModalAsync();
                }
            }
            finally
            {
                this.IsBusy      = false;
                button.IsEnabled = true;
            }
        }