0

I'm making page with 2 tab and each of them have search bar on top of them, the searchbar value on first tab remains when im navigating to other tabs and back to the first tab. How do i remove the state or reference when im navigating to other tab? so when navigating back to the first tab its a new page(no value on the search bar and constructor is triggered) instead of old one(constructor is not triggered).

I'm using xamarin shell.

    <Tab Title="Coffee">
        <Tab.Icon>
            <FontImageSource FontFamily="FAS"
                         Color="{AppThemeBinding 
                                Dark=White, 
                                Light={StaticResource SystemGray5Dark}}"
                         Glyph="{StaticResource IconCoffee}"/>
        </Tab.Icon>
        <ShellContent Title="Light" ContentTemplate="{DataTemplate local:CoffeeEquipmentPage}" Route="CoffeeEquipmentPage" />
        <ShellContent Title="Medium" ContentTemplate="{DataTemplate local:CoffeeEquipmentPage}" Route="CoffeeEquipmentPage2" />
        <ShellContent Title="Dark" ContentTemplate="{DataTemplate local:CoffeeEquipmentPage}" Route="CoffeeEquipmentPage3" />
    </Tab>
    <Tab Title="Espresso">
        <Tab.Icon>
            <FontImageSource FontFamily="FAS"
                         Color="{AppThemeBinding 
                                Dark=White, 
                                Light={StaticResource SystemGray5Dark}}"
                         Glyph="{x:Static fontAwesome:FontAwesomeIcons.MugHot}"/>
        </Tab.Icon>
        <ShellContent Title="tab 2" ContentTemplate="{DataTemplate local:CoffeeEquipmentPage}" Route="CoffeeEquipmentPage3" />
    </Tab>

I've attached gif to show the behaviour. link

William
  • 1
  • 2
  • use the `CurrentPageChanged` event to trigger an action when the user changes tabs – Jason Nov 29 '21 at 11:21
  • i can use the event to clear searchbar value when i navigating to another page, but how to handle when navigate back ? i need to re-new the list since the list will be modified depends on the search bar value – William Nov 30 '21 at 01:26
  • 1
    the event fires every time the page changes, it does not care if you are going **to** or **back** – Jason Nov 30 '21 at 03:22
  • How do i put EventToCommand for CurrentPageChanged on my page? I tried to put ` ` on my Page but it got error "System.Reflection.TargetInvocationException Message=Exception has been thrown by the target of an invocation." – William Nov 30 '21 at 03:37
  • That event fires on the TabbedPage, not the ContentPage – Jason Nov 30 '21 at 03:38
  • I'm using xamarin shell and have no control over the tab navigation and the event. Could you give me some example on how to implement it on Xamarin shell? here's link to my code : https://pastebin.com/qRrRH81f – William Nov 30 '21 at 03:47
  • check this question https://stackoverflow.com/questions/31961425/how-do-i-detect-tab-was-touched-in-xamarin-forms-tabbedpage – Adrain Nov 30 '21 at 07:49

0 Answers0