Hi everyone, I thought I'd share some of my lessons learned to workaround an issue that exists currently with Xamarin Forms Toolbar Items.
The first thing to note is that Android seems to be the weakest implementation compared to iOS or Windows Phone (same as the Editor Text property not updating when initialized in the constructor - see my other post). In iOS, Toolbaritem works as expected and Windows Phone has a slight problem but can be worked around in the same way as Android.
The issue: When navigating away from my home page and going to a detail page the toolbar items that were built and assigned to the Toolbaritems property of the target detail page (this was done in the constructor) were not displayed on Android (even though I could see the items being successfully created ( as I stated, this same forms code runs flawlessly on iOS). I believe the issue was the same on windows phone. I then also noticed that when I moved the toolbar item initialization code from the page constructor to the OnAppearing event, the icons became visible!! I also noted that when I returned to the homepage the toolbar from the detail page was still there where I expected to see the toolbar of the home page. It appears that when one navigates from one page to another the toolbar for the previous page remains visible unless you explicitly clear it....
The solution: I wrapped the toolbar initialization code in a private method (for each page) that is called on the constructor for iOS and on the OnAppearing event on Android and Windows Phone (using the standard Device.OnPlatform technique). I also made sure that the initialization code in the method clears the toolbar before adding any more items and I also added a this.ToolbarItems.Clear(); to the OnDisappearing() event of each page.
So in summary, depending on where you call the code (constructor vs onApppearing event) and whether you explicitly clear toolbars you may find some of these same issues. Of course it would be nice if we could make this work without these workarounds and out of the box like it does for iOS - Hopefully this will be fixed in the next release. I noticed that quite a few other people had similar issues.
Regards,
Luis.