如何创建一个基本的 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>
...
</d:BaseContentPage>
关于xaml - Xamarin 在 Xaml 中继承 ContentPage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44768996/