Toolbar items repeated on Navigation page - WPF (Xamarin Forms)

In my Cross Platform Project, I have added a WPF project as well. I am using a MasterDetail page. I have a page called 'Settings'. This page has 4 icons on the Toolbar. One of the icon is called 'Login' and on click of it, we are navigated to the Login page.
await Navigation.PushAsync(new Login());
On this page, there are no icons on the Toolbar. But in WPF, all the icons of the 'Settings' page are displayed in the Login page as well. I tested it on UWP and Android. It works fine. The Toolbar items are not repeated. But only in WPF this causes issue.

Within the constructor, I kept a check for the count of the Toolbar items, It returns 0. Still when the page is displayed, it contains the icons from the 'Settings' page.
Any help would be greatly appreciated.

Tagged:

Answers

  • ColeXColeX Member, Xamarin Team Xamurai

    Can you provide a simple sample that can reproduce your issue?

  • s_dsouzas_dsouza Member ✭✭

    Hi.
    I have attached 2 images.
    I have a Settings page, Login page and List page. I can navigate from to the Login page from the Settings or List page. As you can see in the images, Settings has a different set of toolbar items compared to the List page. But when we navigate to the Login page, the toolbar items of the calling page are placed on the toolbar of the Login page. (The login page has no toolbar items).

  • s_dsouzas_dsouza Member ✭✭

    Sorry, the images link did not appear in the post. So sending it again.

  • s_dsouzas_dsouza Member ✭✭

    I am not sure, if it can help. This is the xaml for the Login, Settings and List pages.
    The login page has no items in the toolbar.
    The settings page has 2 items, 'Save' and 'Login'
    The List page has 2 items, 'Play' and 'Login'
    As you can see in the screen shots above, the login page has the same icons of the calling page, i.e Screen shot 1 - Login page has the same toolbar items as that of the Settings page.
    Screen shot 2: Login page has the same toolbar items as that of the List page.

    Login Page:

    <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
                 xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                 x:Class="TestV2.Views.Login"
                 Title="">
        <ContentPage.Content>
            <StackLayout>
                 ....
            </StackLayout>
        </ContentPage.Content>
    </ContentPage>
    

    Settings Page:

    <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
                 xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                 x:Class=TestV2.Views.SettingsPage" 
                 Title="">
        <ContentPage.ToolbarItems>
            <ToolbarItem Text="Save" Clicked="btnSaveClicked"  Icon="Icon/icon2.png">
            </ToolbarItem>
            <ToolbarItem Text="Login" Clicked="btnLoginClicked" x:Name="tbLogin" >
             </ToolbarItem>
        </ContentPage.ToolbarItems>
        <ContentPage.Content>
            <StackLayout Orientation="Vertical" VerticalOptions="StartAndExpand">
               ....
            </StackLayout>
        </ContentPage.Content>
    </ContentPage>
    

    List Page:

    ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
                      xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                      x:Class="TestV2.Views.List"
                      Title="">
             <ContentPage.ToolbarItems>
                 <ToolbarItem Text="Play" Clicked="btnPlayClicked"  Icon="Icon/icon3.png" >
                 </ToolbarItem>
                 <ToolbarItem Text="Login" Clicked="btnLoginClicked" x:Name="tbLogin" />
             </ContentPage.ToolbarItems>
             <ContentPage.Content>
                 <StackLayout Orientation="Vertical" VerticalOptions="StartAndExpand" Margin="0,0,0,10">
                  ....
                 </StackLayout>
             </ContentPage.Content>
         </ContentPage>
    
  • s_dsouzas_dsouza Member ✭✭

    I tried it using the code as well.
    i.e. Within OnAppearing(),

    ToolbarItems.Clear();
    ToolbarItem tbPlay = new ToolbarItem();
    tbPlay.Icon = "Icon/iconView.png";
    tbPlay.Text = "View";
    tbPlay.Clicked += btnPlayClicked;
    ToolbarItems.Add(tbPlay);

    I used this code within OnAppearing, because when we click 'Back' from the 'Login' page, 'Initialize' is not called, only OnAppearing is called. But still, it repeats the toolbar items in WPF.

Sign In or Register to comment.