首页 > 解决方案 > MasterDetail页面调试错误:CS0263

问题描述

我定义了一个基本的主详细信息页面。但是每当我尝试启动模拟器时,我都会收到此错误:“CS0263 'MainPage' 的部分声明不能指定不同的基类”它已经 1 周了,仍然无法解决它。我知道这是关于继承,但我该怎么办?有任何想法吗?

<?xml version="1.0" encoding="utf-8" ?>
<MasterDetailPage  xmlns="http://xamarin.com/schemas/2014/forms"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         x:Class="MasterDetail.MainPage">

<MasterDetailPage.Master>
    <ContentPage BackgroundColor="White" Title="Master">
        <StackLayout >
            <StackLayout>
                <Frame BackgroundColor="#48b6a6" >
                    <Image Source="heartbeatt.png" HorizontalOptions="Center" 
   VerticalOptions="Center"/>
                </Frame>
            </StackLayout>
        </StackLayout>

    </ContentPage>
</MasterDetailPage.Master>

<MasterDetailPage.Detail>
    <ContentPage>
        <StackLayout>
            <Label Text="Detail"></Label>
        </StackLayout>
    </ContentPage>
</MasterDetailPage.Detail>
</MasterDetailPage>

cs文件在这里

    using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;

namespace MasterDetail
{
    public partial class MainPage : ContentPage
    {
        public MainPage()
        {
            InitializeComponent();
        }

     
    }
}

标签: xamlxamarinxamarin.formsvisual-studio-2019master-detail

解决方案


这就是问题

public partial class MainPage : ContentPage

在 XAML MainPage 中是一个MasterDetailPage,而不是一个ContentPage. 改为这样做

public partial class MainPage : MasterDetailPage

这正是错误消息告诉您的内容:“不得指定不同的基类”


推荐阅读