Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

Toolbaritem kills navigation to "CurrentPage" on MultiPage (Windows Phone issue)

$
0
0

Hi all,

I stumbled across the following issue, and was hoping someone could help to solve it.

Issue:
When I have a ContentPage without a toolbaritem, and I navigate to a specific page in a Carousel, the Carousel is displayed with the set page as the current page.
When I have a ContentPage with a toolbar item, and I navigate to a specific page in a Carousel, on Windows Only, the Carousel displays the first page, no matter what is done with CurrentPage. On IOs / Android I still navigate to the set page.

Below is the source code that shows the problem.
If you:
- Run on Windows, and you go to page red.
- Run on iOs and you go to page green.
- Remove the toolbaritem, run on Windows, you go to page green.
- Set the toolbaritem to the navigation page instead of the "headPage", run on windows, you go to page green.

`
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

    using Xamarin.Forms;

    namespace CurrentPageToolbarWP
    {
        public class App : Application
        {
            public System.Windows.Input.ICommand GoToPage2 { get; set; }
            Label  aLabel;
            ContentPage headPage;

            public App()
            {
                GoToPage2 = new Command(() => { GoToPage2Proc(); });
                aLabel = new Label {XAlign = TextAlignment.Center, Text = "Welcome!"};
                headPage = new ContentPage
                {
                    Content = new StackLayout
                    {
                        VerticalOptions = LayoutOptions.Center,
                        Children = {
                            aLabel,
                            new Button {
                                Text="Go to carousel page 2",
                                Command=GoToPage2
                            }

                        }
                    }
                };
                MainPage = new NavigationPage (headPage);
                headPage.ToolbarItems.Add(new ToolbarItem("Toolbar", "", () => { ToolbarItemClick(); }));
            }

            private string ToolbarItemClick()
            {
                return aLabel.Text = "Clicked!";
            }

            private void GoToPage2Proc()
            {
                List<ContentPage> pages = new List<ContentPage> (0);
                Color[] colors = { Color.Red, Color.Green, Color.Blue };
                foreach (Color c in colors) {
                    pages.Add (new ContentPage { 
                        Content = new StackLayout {
                            Children = {
                                new Label { Text = c.ToString () },
                                new BoxView {
                                    Color = c,
                                    VerticalOptions = LayoutOptions.FillAndExpand
                                }
                            }
                        }
                    });
                }
                CarouselPage cPage = new CarouselPage
                {
                    Children = { 
                        pages [0],
                        pages [1],
                        pages [2] }
                };
                var multiPage = (MultiPage<ContentPage>)cPage;
                Device.BeginInvokeOnMainThread(() =>
                {
                    multiPage.CurrentPage = multiPage.Children[1];
                });
                ((NavigationPage)MainPage).PushAsync(cPage);
            }
        }
    }

`


Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>