简体   繁体   中英

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?

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

<d:BaseContentPage>
  ...
</d:BaseContentPage>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM