I am trying to implement a BasePage that subclasses ContentPage in a pcl library. I then would like to inherit pages from that subclass. I cannot seem to get this going. Has anyone actually accomplished this with Xamarin Forms? I could be missing something simple, so I've created a simple solution to repro the problem and I've attached that to my post.
It seems to stem from the .g.cs file being generated:
public partial class AwesomePage : global::ConceptSubclassBasePage.Library.PageBase {
private void InitializeComponent() {
this.LoadFromXaml(typeof(AwesomePage));
}
}
It is looking for the PageBase in Library, even though the namespace is actually ConceptSubclassBasePage.Library.Bases. Here is my other code:
In Xaml code-behind:
public partial class AwesomePage : ConceptSubclassBasePage.Library.Bases.PageBase
{
public AwesomePage ()
{
InitializeComponent ();
}
}
In Xaml:
<?xml version="1.0" encoding="UTF-8"?>
<bases:PageBase xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:bases="ConceptSubclassBasePage.Library.Bases"
x:Class="Pages.AwesomePage">
<bases:PageBase.Content>
</bases:PageBase.Content>
</bases:PageBase>
And here is the code for PageBase:
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="ConceptSubclassBasePage.Library.Bases.PageBase">
<ContentPage.Content>
</ContentPage.Content>
</ContentPage>
namespace ConceptSubclassBasePage.Library.Bases
{
public partial class PageBase : ContentPage
{
public PageBase ()
{
InitializeComponent ();
}
}
}
Possibly related to this is that I have hierarchical namespaces checked in project options both for my environment and the individual projects, and this doesn't seem to work. Every time I add a file, I have to remember to change the namespace of the generated file from e.g. namespace Bases to namespace App.Library.Bases.
What am I missing!? :-\
Thanks in advance!? ;-)