xaml - Xamarin 在 Xaml 中继承 ContentPage

标签 xaml inheritance xamarin xamarin.forms

如何创建一个基本的 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/

相关文章:

C++:有没有办法指定一个从另一个继承的泛化类?

xamarin - Xamarin Forms View 不使用自定义类更新

c# - 在 Xamarin MAC 应用程序中检测 Wifi SSID

wpf - 禁用 WPF TreeView(或 TreeViewItem)选择?

c# - 使用BackgroundWorker交换绑定(bind)属性的对象引用

xaml - Bing MapControl WP7 XAML 数据绑定(bind)中心

c# - 将自定义依赖属性绑定(bind)到自定义 WPF 样式

java - Hibernate:是否可以将多级继承映射到单个表?

c++ - C++ 中的继承 : Order of Construction

c# - 从 Azure 中的 SOAP Web 服务检索列表时出现 TargetInitationException