Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xamarin Inherit ContentPage in Xaml

How can one create a base contentpage class to inherit from with xamarin forms?

I followed this forum for advice.

Everything is fine until I have to address the Xaml portion.

using System;
using Xamarin.Forms;

namespace MyProject
{
    public class BaseContentPage : ContentPage
    {
        public BaseContentPage()
        {
        }
    }
}


using System;

using Xamarin.Forms;

namespace MyProject
{
    public partial class DashboardPage : BaseContentPage
    {
        public DashboardPage()
        {
            InitializeComponent();
        }

        void GoToJobDetailsPage(object sender, EventArgs args)
        {
            var masterPage = Application.Current.MainPage as MasterDetailPage;
            masterPage.Detail = new H2HNavigationPage(new JobDetailPage());
        }
    }
}


<?xml version="1.0" encoding="UTF-8"?>
<d.BaseContentPage
    xmlns="http://xamarin.com/schemas/2014/forms" 
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:d="clr-namespace:MyProject;assembly=MyProject"
    x:Class="MyProject.DashboardPage"
    ControlTemplate="{StaticResource Background}">
    <ContentPage.Content>

    </ContentPage.Content>
</d.BaseContentPage>

When I do this I get the compiler error

...DashboardPage.xaml.g.cs(64,64): Error CS0234: The type or namespace name 'd' does not exist in the namespace 'Xamarin.Forms' (are you missing an assembly reference?) (CS0234)

Of course, I can figure that d alias is not in scope but what am I to do to create a custom base class content page?

like image 500
mac10688 Avatar asked Jun 26 '17 21:06

mac10688


1 Answers

in XAML, use ":" as the separator between the namespace and classname

<d:BaseContentPage>
  ...
</d:BaseContentPage>
like image 79
Jason Avatar answered Oct 10 '22 22:10

Jason