dynamic tabbar in xamarin.forms shell?

mc 3,641 Reputation points
2020-11-23T02:18:59.647+00:00

<ShellContent Title="title" Icon="icon.png" Route="IndexPage" ContentTemplate={DataTemplate local:IndexPage} />

can it be changed dynamiclly?

the title icon route and contentTemplate?

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,292 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 68,261 Reputation points Microsoft Vendor
    2020-11-23T08:10:44.953+00:00

    Hello,​

    Welcome to our Microsoft Q&A platform!

    Yes, you can.

    First of all, Here is my xaml code. I have TabBar, then I want to change the aboutPage, It is the first items in the TabBar

       <TabBar x:Name="MyTabbar">  
               <ShellContent x:Name="MyShellcontent1" Title="About" Icon="icon_about.png"  ContentTemplate="{DataTemplate local:Page1}" />  
               <ShellContent Title="Browse" Icon="icon_feed.png" ContentTemplate="{DataTemplate local:ItemsPage}" />  
           </TabBar>  
    

    In the shell's background code. we can change it by following code. I used MessagingCenter to execute it.

       public partial class AppShell : Xamarin.Forms.Shell  
           {  
               public AppShell()  
               {  
                   InitializeComponent();  
                   Routing.RegisterRoute(nameof(ItemDetailPage), typeof(ItemDetailPage));  
                   Routing.RegisterRoute(nameof(NewItemPage), typeof(NewItemPage));  
         
         
                   MessagingCenter.Subscribe<App, string>(App.Current, "OneMessage", (snd, arg) =>  
                   {  
         
                     //Change the title icon route and contentTemplate  
                       ((AppShell)Shell.Current).MyTabbar.Items[0] = new ShellContent { Icon= "StarChecked.png",Title="test", Content = new AboutPage() };  
                   });  
         
         
         
               }  
         
           }  
    

    Here is running GIF.

    41824-shell.gif

    Best Regards,

    Leon Lu


    If the response is helpful, please click "Accept Answer" and upvote it.

    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.

    1 person found this answer helpful.
    0 comments No comments