Hello,
You can achieve this NavigateTo
in the AppShell backgroud code.
Then we can get the current selected ShellItem.then traverse IList<ShellSection>
, if get the same title, change the current CurrentItem by Shell.Current.CurrentItem.CurrentItem= shellSection;
and close this Flyout page with Shell.Current.FlyoutIsPresented = false;
public partial class AppShell : Shell
{
public ICommand NavigateTo { get; set; }
public AppShell()
{
InitializeComponent();
Routing.RegisterRoute("CatsPage", typeof(CatsPage));
Routing.RegisterRoute("DogsPage", typeof(DogsPage));
Routing.RegisterRoute("MainPage", typeof(MainPage));
Routing.RegisterRoute("MonkeysPage", typeof(MonkeysPage));
NavigateTo = new Command((e) =>{
BaseShellItem res = e as BaseShellItem;
IList<ShellSection> shellSections= Shell.Current.CurrentItem.Items;
foreach (ShellSection shellSection in shellSections)
{
if(res.Title.Equals(shellSection.Title))
{
Shell.Current.CurrentItem.CurrentItem= shellSection;
Shell.Current.FlyoutIsPresented = false;
}
}
});
BindingContext = this;
}
}
Please do not forget to add Title for your <Tab>
or <ShellContent>
like following code.
<FlyoutItem FlyoutDisplayOptions="AsMultipleItems">
<Tab Title="Domestic"
Icon="paw.png">
<ShellContent Title="Cats"
Icon="cat.png"
Route="CatsPage"
ContentTemplate="{DataTemplate local:CatsPage}" />
<ShellContent Title="Dogs"
Icon="dog.png"
Route="DogsPage"
ContentTemplate="{DataTemplate local:DogsPage}" />
</Tab>
<ShellContent Title="Monkeys"
Icon="monkey.png"
Route="MonkeysPage"
ContentTemplate="{DataTemplate local:MonkeysPage}" />
</FlyoutItem>
As note:Avoid duplicate questions in one thread
Best Regards,
Leon Lu
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.