I have a Xamarin Forms App and I want to put a standard (sub)header on every page. The subheader will contain a label which will change for each page and an optional back button, and will be just below the App Header which contains the menu hamburger and the App Name.
Initially I created a "HeaderPage" which contained the layout for the standard controls, and all my pages inherited from this page. I "hid" the ContentPage.Content so the pages that inherited from HeaderPage could just set Content = to set the HeaderPage Content
private ContentView _headerPageContent;
public new View Content
{
set { _headerPageContent.Content = value; }
}
and the child page just had to set the text:
HeaderLabel = "Contact Us";
This worked great until Forms 2.1 where the ability to mask ContentPage.Content was removed.
At that time the recommendation was to use a ContentPage with a ControlTemplate that has the header. I explored this path, as did one of my co-workers, and we both backed off because of the complexity and duplication of code putting the binding on every page.
I've thought about making the heading a view, or looking into what it would take to make it a control.
For now I took the easy way out and renamed the "Content" variable to "HeaderPageContent" so all the pages that inherit from Header page set HeaderPageContent instead of Content.
Has anyone else done something similar to this? What have you found?