ReSelect the current tab to refresh the Page on TabView Control on Xamarin Community Toolkit

Viewed 102

I am working on a Xamarin Forms App. Everything is working correctly. I am working on a feature where user re-selects the current tab (This tab is already selected) and page should refresh.

I am using TabView from Xamarin Community Toolkit.

There is on code to share as I am looking for some generic solution and my code is running correct.

Is there any way we can write Custom Renderer for Xamarin Toolkit TabView to Re-Select the current tab?

1 Answers

Maybe you needn't use the custom renderer, you can try to use the TabView.SelectedIndex = to re-select the current tab. Such as:

In the xaml:

<xct:TabView TabStripPlacement="Bottom" IsSwipeEnabled="False"  x:Name="tabview">

In the page.cs:

 private void Button_Clicked(object sender, EventArgs e)
    {
        tabview.SelectedIndex = 0;
    }

In addition, user re-select the current tab always by tapping the tabitem, so you can just refresh the page by doing something in the tapped event. Such as:

In the xaml:

<xct:TabView TabStripPlacement="Bottom" IsSwipeEnabled="False"  x:Name="tabview">
        <xct:TabViewItem Text="Data" TabTapped="TabViewItem_TabTapped">
            
        </xct:TabViewItem>

In the page.cs

private void TabViewItem_TabTapped(object sender, Xamarin.CommunityToolkit.UI.Views.TabTappedEventArgs e)
    {
        //doing something
    }
Related