Duplicate toolbar menu

Hi all. I am newbie in Xamarin and now I to face a such problem:
When I add an item in Toolbar menu this item is duplicated

MasterDetailPage:

       <?xml version="1.0" encoding="utf-8" ?>
       <MasterDetailPage xmlns="http://xamarin.com/schemas/2014/forms"
                                     xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                                   x:Class="Reactive.Mobile.Pages.RootPage">

          <MasterDetailPage.ToolbarItems>
                <ToolbarItem Name="Profile" Icon="User-40.png" Activated="OnClick"  Order="Primary" Priority="0" />
           </MasterDetailPage.ToolbarItems>
        </MasterDetailPage>


     public partial class RootPage : MasterDetailPage
    {
        public RootPage ()
        {
        var menuPage = new MenuPage();       

        menuPage.OnMenuSelect = (categoryPage) =>
        {
            Detail = new NavigationPage(categoryPage);
            IsPresented = false;
        };

        Master = menuPage;

        Detail = new NavigationPage(new Profile());
    }

    void OnClick(object sender, EventArgs e)
    {
        ToolbarItem tbi = (ToolbarItem)sender;
        this.DisplayAlert("Selected!", tbi.Name, "OK");
    }
}

Answers

  • MommMomm USMember ✭✭✭

    @Kakao_Developer, you should not add it to your MasterDetailPage, only add it to your DetailPage.

  • @Momm, ok, now code with ToolbarItem only on page Reservation

             <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
                                       xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                                       x:Class="Reactive.Mobile.Reservation">
                 <ContentPage.ToolbarItems>
                         <ToolbarItem Name="Profile" Icon="User-40.png"/>
                 </ContentPage.ToolbarItems>
                   .....
    

    but problem no solved

    any ideas?))

  • MommMomm USMember ✭✭✭
    edited August 2016

    I don't have your full source code, but I noticed something weird.

    You should only create a NavigationPage once (in the constructor) and then, to change its page, you should call PushAsync (in the OnMenuSelected event), something like this.

    • ((NavigationPage)Detail).PushAsync(categoryPage);

    Not sure if it is the cause of your problem or not.

  • I had this same issue. It turned out the problem was in my App.cs I had the following code...
    MainPage = new NavigationPage(new MyApp.Home());

    I changed it to
    MainPage = new MyApp.Home();

    and the duplicate toolbar went away.

Sign In or Register to comment.