Forum Cross Platform with Xamarin
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

Back button with carousel

I want the hardware back button to behave like a right to left swipe gesture within a carousel. I am not using a navbar.I tried over riding the OnBackButtonPressed event and adding a PushAsync to the previous carousel page. This works, but the carousel no longer works - as expected once I understood what the PushSync did. Any ideas?

Answers

  • jezhjezh Member, Xamarin Team Xamurai

    Could you please post a basic demo so that we can test with it?

  • mcourtermcourter Member ✭✭

    I try to cobble something together.
    Right now I am simply giving users the option to stay or go.
    Here's what's in the .cs for one of the .xaml pages within the carousel:

    using MvvmCross.Forms.Views.Attributes;
    using myInventory.Models;
    using Xamarin.Forms;
    using System;

    namespace myInventory.Pages
    {
    [MvxCarouselPagePresentation(CarouselPosition.Carousel)]
    public partial class mySelectionsPage
    {
    public mySelectionsPage()
    {
    InitializeComponent();
    }
    protected override bool OnBackButtonPressed()
    {
    // Begin an asyncronous task on the UI thread because we intend to ask the users permission.
    Device.BeginInvokeOnMainThread(async () =>
    {
    if (await DisplayAlert("Exit page?", "Are you sure you want to exit this page? You will be logged out.", "Yes", "No"))
    {
    base.OnBackButtonPressed();

                    //this removes the previous page from the stack
                    //Navigation.RemovePage(Navigation.NavigationStack[Navigation.NavigationStack.Count - 2]);
    
                    await Navigation.PopAsync();
    
                    //this pops the page but kills the carousel
                    //myListPage pelp = new myListPage();
                    //await Navigation.PushAsync(pelp);
                }
            });
    
            // Always return true because this method is not asynchronous.
            // We must handle the action ourselves: see above.
            return true;
        }
    }
    

    }

Sign In or Register to comment.