[UWP] ToolBarItem icon is not shown on first page

InregoInrego DKMember ✭✭

When my application loads, no icon is shown in my ToolBarItem. See below screenshot:

If I click a menu item that opens the same page again, then the icon shows correctly:

There isn't a lot of magic to my page, and the ToolBarItem is pretty simple:

Any ideas for why it doesn't show on first load?

Answers

  • InregoInrego DKMember ✭✭

    Update: Even if I navigate to another page in the OnStart function in App.cs, the new page doesn't show any icons either.
    So only when I manually navigate to a page, I guess.

  • juyojuyo USMember ✭✭

    I have exactly same issue

  • stev_estev_e Member ✭✭

    Same for me (XF 3.4)

  • JohnHardmanJohnHardman GBUniversity mod

    Using XF 3.3, I see toolbar items appearing correctly for my main page. I populate the page and toolbar items in OnAppearing() rather than in the page's constructor. You might want to move your toolbar item code to OnAppearing to see if that works for you (only add the items the first time OnAppearing is called).

    @Inrego said:
    Update: Even if I navigate to another page in the OnStart function in App.cs, the new page doesn't show any icons either.
    So only when I manually navigate to a page, I guess.

    Calling async methods from lifecycle overrides can introduce race conditions. On UWP, this can cause all sorts of weirdness (the back button not appearing is the one that I used to see regularly). Do not use async methods in lifecycle overrides unless those methods are truly fire and forget, and are hence not awaited. I reported the back button problem back in the days of Bugzilla, but even with a repro sample that demonstrated the problem as reliably as any UI race condition can be demonstrated, the Xamarin Forms team could not see the problem. Hence, my advise about not calling awaited async methods from lifecycle overrides.

  • ShantimohanElchuriShantimohanElchuri USMember ✭✭✭✭✭

    @Inrego @juyo @stev_e The Toolbar is available when you open a page using Navigation service. When you say 'First Page' I assume it is the MainPage called from App.xaml.cs. If so you should be calling it as below:

    MainPage = new NavigationPage(new MainPage());

    When you say the ToolbarItem is visible when called from a MenuItem, then I suppose above reason is the cause of your issue. You are using NavigationPage from the MenuItem but not from App.xaml.cs

  • stev_estev_e Member ✭✭

    Hi Shantimohan, thank you for your suggestions. I use a Master-Detail-Navigation (provided by FreshMvvm but I think that is not the point). The buttons are "there" and can be clicked. Only the icon is missing. Then, when I for example tick the hamburger menu (without invoking any real navigation) the icons get visible. Android is working. The toolbar items are defined in XAML.

  • FloIriumFloIrium Member

    @stev_e said:
    Hi Shantimohan, thank you for your suggestions. I use a Master-Detail-Navigation (provided by FreshMvvm but I think that is not the point). The buttons are "there" and can be clicked. Only the icon is missing. Then, when I for example tick the hamburger menu (without invoking any real navigation) the icons get visible. Android is working. The toolbar items are defined in XAML.

    Hello, we have exactly the same problem

Sign In or Register to comment.