Sreejith Sree
Sreejith Sree

Reputation: 3681

Xamarin Forms: How to set title for tabbedpage?

I implement TabbedPage with 3 tabs like the following picture.

enter image description here

On top of these 3 tabs, I am trying to set a title, which will be common for all the 3 tabs. Tried title property of tabbedpage, but not worked.

MyTabbedpage.xaml

<?xml version="1.0" encoding="utf-8" ?>
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
            xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
            xmlns:local="clr-namespace:Myapp;assembly=Myapp"
            BarBackgroundColor="#1C7DB4"
            BarTextColor="White"
            x:Class="Myapp.MyTabbedPage">
</TabbedPage>

MyTabbedpage.xaml.cs

using Xamarin.Forms;
using Xamarin.Forms.Xaml;

namespace Myapp
{
    [XamlCompilation(XamlCompilationOptions.Compile)]
    public partial class MyTabbedPage : TabbedPage
    {
        public MyTabbedPage(bool value)
        {
            InitializeComponent();

            Children.Add(new Topics());
            Children.Add(new Group());
            Children.Add(new Menu());
        }

        protected override bool OnBackButtonPressed()
        {
            return false;
        }
    }
}

enter image description here

Please suggest a solution.

Upvotes: 0

Views: 4684

Answers (2)

EvZ
EvZ

Reputation: 12179

public class MainPageCS : TabbedPage
{
  public MainPageCS ()
  {
    var navigationPage = new NavigationPage (new SchedulePageCS ());
    navigationPage.Icon = "schedule.png";
    navigationPage.Title = "Schedule";

    Children.Add (new TodayPageCS ());
    Children.Add (navigationPage);
  }
}

This is the code snippet from the official documentation. On line number 7 you can see how the title is set.

After you edited your question, it seems that you want to wrap your TabbedPage by a NavigationPage and set a Title for the NavigationPage. Example:

new NavigationPage(new MyTabbedPage()) { Title = "Common Title" }; 

Alternatively, one of your TabbedPage children can be a NavigationPage as well, depends on your needs.

Upvotes: 0

Calin Vlasin
Calin Vlasin

Reputation: 1433

I don't think you can do it without a custom renderer.

You may try this prebuilt form control - TabView - found at: https://github.com/gruan01/XFControls

You can find it also on NuGet. You can set image onto the tabs and other enhancements.

But I strongly recommend a custom renderer as a final solution.

Upvotes: 1

Related Questions