首页 文章

Xamarin在Xaml中继承ContentPage

提问于
浏览
3

如何创建一个基础内容页面类来继承xamarin表单?

我跟着这个forum寻求建议 .

一切都很好,直到我必须解决Xaml部分 .

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>

当我这样做时,我得到编译器错误

...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)

当然,我可以认为d别名不在范围内,但我该怎么做才能创建自定义基类内容页面?

1 回答

  • 6

    在XAML中,使用“:”作为命名空间和类名之间的分隔符

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

相关问题