Navigation between shell content

wlchoy96wlchoy96 Member ✭✭

I have three pages in my shell (1,2,3). Page 2 is a list of item. Is it possible for me to click the item in page 2 to first go to page 1 and open a new page( page 4) with the passing of a parameters?

Answers

  • LeonLuLeonLu Member, Xamarin Team Xamurai
    edited October 1

    First of all, you can register your pages wiht following code.

      Routing.RegisterRoute("monkeydetails", typeof(MonkeyDetailPage));
    

    You can passing of parameters

        await Shell.Current.GoToAsync($"//animals/elephants/elephantdetails?name={elephantName}");
    

    Then, get the parameters from other pages.

          [QueryProperty("Name", "name")]
         public partial class ElephantDetailPage : ContentPage
         {
            public string Name
         {
           set
         {
            BindingContext = ElephantData.Elephants.FirstOrDefault(m => m.Name == Uri.UnescapeDataString(value));
        }
        }
    .
    

    If you want to know more details about it, please read the following link.
    https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/shell/navigation

  • wlchoy96wlchoy96 Member ✭✭

    I just want to switch between tab not navigate to the page

  • LeonLuLeonLu Member, Xamarin Team Xamurai

    Do you want to pass of a parameters between two tabs? If so, you can use messageCenter to achieve that.

  • wlchoy96wlchoy96 Member ✭✭

    My situation is like this...I have a map which is page 1, list of location which is page 2 and description which is page 3. When i click the spot on my map on page 1, it will navigate to the detail page, page 4. Now I am using one shell to hold all page 1,2,3 and clickevent on page 1 to page 4 using (await Shell.Current.GoToAsync($"location?code={loc}"))

  • wlchoy96wlchoy96 Member ✭✭

    Since I have opened page 4 at page 1 before and I still can go to page 2..so if I opened page 4 at page 2 it will be have two page 2 in one shell

  • wlchoy96wlchoy96 Member ✭✭

    So is it possible for me to open page 4 from page 1 when I trigger an click event on page 2

  • LeonLuLeonLu Member, Xamarin Team Xamurai

    First of all, I cannot Imagine what is specific achievement for your application, Could you provide a specific demo?

    @wlchoy96 said:
    So is it possible for me to open page 4 from page 1 when I trigger an click event on page 2

    Then, base on your needs, you can add a MessagingCenter.Send() method in your click event of Page2 like following code.

        private void Btn_Click(object sender, EventArgs e)
        {
            MessagingCenter.Send<object, string>(this, "ShowAlertMessage", "StackOverFlow Rocks");
        }
    

    Add the MessagingCenter.Subscribe method in your page 1, when you execute the click event of Page2, Page1 will get a message to open the Page4

             public  Page1(){
             MessagingCenter.Subscribe<object, string>(this, "ShowAlertMessage", (sender, msg) =>
              {
                await Shell.Current.GoToAsync($"//animals/page4");
    
               });
           }
    
Sign In or Register to comment.