In Xamarin.Forms, I'm trying to create a page that I then subclass, like this:
public partial class PageA : ContentPage {
public PageA() {InitializeComponent ();}
}
public partial class PageB : PageA {
public PageB() : base() { ... }
}
Both of these pages are xaml pages with code behinds, but the PageB page is not working and I'm not sure why (I'm new to XAML, Xamarin, C# and basically coding in general).
I can't compile the code at the moment, since this line:
this.FindByName<Label>
gives me a warning of:
PageB does not contain a definition for 'FindByName', and the best extension method ... requires a receiver of type 'Element'
And this line:
await Navigation.PushAsync(new PageB());
gives an error that PageB is not an Xamarin.Forms.Page. I don't know why PageA would be considered such a type, but it is.
Questions:
- Is it possible to create subclasses of custom pages?
- Why is a class that subclasses ContentPage (PageA) considered to be both of type 'Element' and of type 'Page'? And why is PageB NOT considered to be of those types?
I suspect I'm wildly off in many things here, so any corrections in how I've phrased the question and pointers to what question I SHOULD be asking are greatly welcome!
=========== EDIT
In response to a comment below:
PageA
The .cs file (codebehind) has the namespace AppName.FolderName, and the xaml has the x:Class attribute value x:Class="AppName.FolderName.PageA"
<?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="AppName.FolderName.PageA">
... (some elements) ...
</ContentPage>
PageB
The .cs file (codebehind) has the namespace AppName.FolderName.SubFolderName, and the xaml has the x:Class attribute value x:Class="AppName.FolderName.SubFolderName.PageB"
And I have a reference with the following using AppName.FolderName, which gives me access to the PageA class
<?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="AppName.FolderName.SubFolderName.PageB">
</ContentPage>