예제 #1
0
        /// <summary>
        /// Method callback for when the edit button is clicked.
        /// </summary>
        /// <param name="sender">Object that sent the click event.</param>
        /// <param name="e">Event arguments for the click event.</param>
        private async void EditButton_Clicked(object sender,
                                              System.EventArgs e)
        {
            // Only continue execution if the page is unlocked
            if (this.locked)
            {
                return;
            }
            this.locked = true;

            // Create the page to edit the horse and navigate to it
            Page page = new HorseEditPage(this.horse);

            await this.Navigation.PushAsync(page, true);

            // Unlock the current page after navigation has occurred
            this.locked = false;
        }
예제 #2
0
        /// <summary>
        /// Method to be called when the "add horse" button is pressed.
        /// </summary>
        /// <param name="sender">The item that triggers the event.</param>
        /// <param name="e">The event args for the event.</param>
        private void AddHorseButton_Clicked(object sender, EventArgs e)
        {
            // If the current modal page is set to be locked, do not render a
            // horse modal page
            if (this.locked)
            {
                return;
            }

            // Lock the main thread from opening another page until the current
            // modal display has been closed
            this.locked = true;

            // Invoke a separate operation to create a horse.
            Device.BeginInvokeOnMainThread(async() => {
                try {
                    // Prompt the user for the type of horse that they want to
                    // create, from the types that are available.
                    const string StandardHorseString  = "Standard";
                    const string MiniatureHorseString = "Miniature";
                    const string CancelString         = "Cancel";
                    string result = await this.DisplayActionSheet(
                        "Select A Horse Type",
                        CancelString,
                        null,
                        StandardHorseString,
                        MiniatureHorseString);

                    // Handle the result accordingly
                    HorseType type = HorseType.Standard;
                    switch (result)
                    {
                    // Handle when a standard horse is selected
                    case StandardHorseString:
                        type = HorseType.Standard;
                        break;

                    // Handle when a miniature horse is selected
                    case MiniatureHorseString:
                        type = HorseType.Miniature;
                        break;

                    // Handle when the "cancel" button was pressed, or the
                    // user selects outside the bounds of the select.
                    case CancelString:
                    default:
                        return;
                    }

                    // Get a new horse from the horse manager
                    Horse horse = await HorseManager.GetInstance()
                                  .Create(type);

                    // Push a modal to the top of the navigation stack to
                    // display the selected horse's information
                    Page horsePage = new HorseEditPage(horse);
                    await this.Navigation.PushAsync(horsePage);
                } catch (TooManyHorsesException) {
                    // Show a toast indicating that the horse could not be found
                    ToastController.ShortToast("Cannot create any more horses.");
                } finally {
                    // Unlock the page after the modal has been created
                    this.locked = false;
                }
            });
        }