【发布时间】:2017-06-26 21:30:41
【问题描述】:
如何创建一个基本的 contentpage 类以从 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 别名不在范围内,但我该怎么做才能创建自定义基类内容页面?
【问题讨论】:
-
在XAML中,使用“:”作为命名空间和类名的分隔符,即
<d:BaseContentPage> -
就是这样。如果您想做出正式回复,我会将其标记为答案。可耻的是我自己没有看到这一点。谢谢!
标签: xaml inheritance xamarin xamarin.forms