I'm using Xamarin.Forms to build an iOS/Android app, and have a TabbedPage.
If a user is already on Tab 2, and Tab2 is clicked, and I want either the tab2 to refresh, or for a function of my own to run so I can refresh it myself.
Is there a way to do this within Xamarin.Forms or a way to do it with custom renderers?
You can put each tab in a different page then when any page is tabbed the
Override on Appearing()
method is invoked u can from there update the values.Do some research of Android Native
TabLayout
the click event call back function isOnTabReselected
And according to the TabbedPageRenderer source code. You can find
OnTabReselected
is not be implemented.So I created a customer render for
TabbedPage
as following code and implement theOnTabReselected
function to change the current page background :Here is how I ended up solving the issue. My TabbedPage consisted of a NavigationPage for each tab, so if you are not using navigation pages your code will have to change a little bit but only slightly. You can put your "refresh" logic inside of
OnTabbarControllerItemSelected
for iOS andOnTabbarControllerItemSelected
for Android. Check out the code below.Android Renderer (courtesy of Mike Ma)
iOs Renderer: