mac*_*688 3 inheritance xaml xamarin xamarin.forms
如何创建一个基础内容页面类来继承xamarin表单?
我跟着这个论坛寻求建议.
一切都很好,直到我必须解决Xaml部分.
using System;
using Xamarin.Forms;
namespace MyProject
{
public class BaseContentPage : ContentPage
{
public BaseContentPage()
{
}
}
}
Run Code Online (Sandbox Code Playgroud)
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());
}
}
}
Run Code Online (Sandbox Code Playgroud)
<?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>
Run Code Online (Sandbox Code Playgroud)
当我这样做时,我得到编译器错误
...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)
Run Code Online (Sandbox Code Playgroud)
当然,我可以认为d别名不在范围内,但我该怎么做才能创建自定义基类内容页面?
在XAML中,使用":"作为命名空间和类名之间的分隔符
<d:BaseContentPage>
...
</d:BaseContentPage>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2606 次 |
| 最近记录: |