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.
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.