A while back, I wrote about how to handle reselecting/retapping of tabs in a Xamarin.Forms TabbedPage (covering iOS and Android in part 1 here and UWP and NavigationPage in part 2 here). The basic problem is that app designs frequently want to react to a user selecting the already-active tab on a TabbedPage — reselecting, or retapping, the tab. Sometimes the app might want to pop the navigation stack, or perhaps it would scroll to the top of a ListView. Whatever the desire, Xamarin.Forms does not make it easy to catch these reselect events.
A lot has happened since the initial solution presented in the above-mentioned posts, for instance Xamarin.Forms has moved from version 2.3 to version 3.6, and tab icons are supported across the three platforms in the sample (iOS, Android, UWP).
If you’re only interested in iOS and Android, there’s nothing new here. If you need to know how to do this for UWP, read on!
Adding Icons to Tabs
Icons are now supported on tabs on all three of the platforms implemented by this app, just set the Icon property on the immediate children of the TabbedPage. The Image resource must be in the platform-specific projects; shared assembly resources cannot be used for tab Icons.
Unlike iOS and Android, UWP does not support icons on tabs by default. In order to enable tab icons on UWP, the XAML declaration for the TabbedPage needs to be updated:
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:windows="clr-namespace:Xamarin.Forms.PlatformConfiguration.WindowsSpecific;assembly=Xamarin.Forms.Core"
x:Class="TabReselectDemo.MainPage"
windows:TabbedPage.HeaderIconsEnabled="true">
Continue reading “Tab Retap in Xamarin.Forms, Now With Icons!”