2

This link describes how to setup a control template. The control template can be used inside the ContentPage declaration of a content page, as such:

ControlTemplate="{StaticResource MainPageTemplate}"

But the same cannot be done in a TabbedPage. The following is shown:

The property 'ControlTemplate' was not found in type 'TabbedPage'.

I want to use the ControlTemplate to create a custom navigation bar as explained in this tutorial.

The following is the workaround I thought of and tried until now.

Given this navigation stack:

--- App.xaml - MainTabbedPage.xaml - Page1.xaml/Page2.xaml

1) I have created a 'ControlTemplate' in App.Xaml which defines how I want my navigation bar to look like.

2) Removed the default NavigationBar by using the below line in MainTabbedPage.:

NavigationPage.SetHasNavigationBar(this, false);

3) and set the follow line in Page1.xaml and Page2.xaml:

ControlTemplate="{StaticResource MainPageTemplate}"

This does remove the default navigation bar, and does show the custom navigation bar as defined within the ControlTemplate, however, the Tabbed menu shows in the first row, whereas the custom navigation bar shows in the second row. Naturally, I would like it to be the other way round.

Any workarounds that do not entail also create a custom tabbed navigation page? Perhaps any way to extend the Xamarin Forms default tabbed page? Or something different I can do in the aforementioned incomplete workaround?

Jurgen Cuschieri
  • 658
  • 14
  • 33
  • TabbedPage just "hosts" pages, it's not the page itself. How do you expect her to have a template, when she is just a shell for others pages to use ? Makes sense to not have that property – Greggz Sep 17 '18 at 15:06
  • What they do in that tutorial is not a custom navigation bar, it's a page that has a header, it's all made up. Unless you want to create your own tabs, I say what you' re trying to do is not achievable **I think**. – Greggz Sep 17 '18 at 15:08
  • 2
    I did not debate whether it makes sense or not to use the control template. rather, whether I can use a custom navigation bar (or header, or whatever you want to call it) with the Xamarin forms tabbed page. Do you think the only way to do it would be by creating a custom implementation for the tabbed pages too? – Jurgen Cuschieri Sep 17 '18 at 15:10
  • Yes I do, perhaps you would need a Grid with 3 rows, one for the Header, one for your Tabs, and the other for the rest of your content – Greggz Sep 17 '18 at 15:11
  • But straining away from that tutorial, you might want to look at this https://www.xamboy.com/2017/12/06/navigation-bar-customization-in-xamarin-forms/ and just make your own `Navigation Bar` as a component. That would be cleaner and you would not need `Control templates`. Or just use his `Custom Navigation Bar` implementation – Greggz Sep 17 '18 at 15:16
  • I had run into this, and correct me if I'm wrong, but it seems like this implementation does not take images into consideration. I may try and customise a bit more to try to achieve the logo part too though, if all else fails. – Jurgen Cuschieri Sep 18 '18 at 07:07

0 Answers0