RedZ
RedZ

Reputation: 1013

Xamarin Shell FlyoutItem's tab click event

Im using Xamarin forms, and on my AppShell, i want 2 tabs, i want to have a clicked event on one of the tabs, so that when clicked on it doesnt load another page but actually execute a function (show an Rg.Popup on top of the current page).

So i need a way to capture the tab clicked event or maybe a command or anything.

here is what i have:

<FlyoutItem FlyoutDisplayOptions="AsSingleItem" IsVisible="False">
    <Tab Title="001">
        <ShellContent ContentTemplate="{DataTemplate local:HomePage}"></ShellContent>
    </Tab>
    <Tab Title="002">
        <ShellContent ContentTemplate="{DataTemplate local:ProfilePage}"></ShellContent>
    </Tab>
</FlyoutItem>

Upvotes: 0

Views: 4586

Answers (2)

Dan
Dan

Reputation: 184

1 year too late but hope this helps. you can use menuItem which will display ontop of flyoutitem

<MenuItem Text="item" StyleClass="MenuItemLayoutStyle" Clicked="OnClickMethod">
    </MenuItem>

Upvotes: 2

nevermore
nevermore

Reputation: 15816

Create a class inherit from TabBar and override the method OnPropertyChanged:

 public class MyTab : TabBar
    {        
        protected override void OnPropertyChanged([CallerMemberName] string propertyName = null)
        {
            if (propertyName == "CurrentItem")
            {
                int index = this.Items.IndexOf(this.CurrentItem);
                
                if(index == 0)
                {
                    
                }
                if(index == 1)
                {
                    
                }

            }
        }
    }

Use it in Xaml

 <local:MyTab>
    <Tab Title="Browse" Icon="tab_feed.png" x:Name="tab1">
        <ShellContent ContentTemplate="{DataTemplate local:ItemsPage}" />
    </Tab>
    <Tab Title="About" Icon="tab_about.png">
        <ShellContent ContentTemplate="{DataTemplate local:AboutPage}" />
    </Tab>
</local:MyTab>

Another way I thought is that you can execute the function in the page's OnAppearing method.

Upvotes: 1

Related Questions