0
votes

I'm trying to learn Xamarin and I was doing a simple MasterDetailPage to run on iOS. After running the code I got this error:

Can not set the content of MasterDetailPage as it doesn't have a ContentPropertyAttribute

Below is my XAML file code snippet:

<?xml version="1.0" encoding="utf-8"?>
<MasterDetailPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:MasterDetailLearing" x:Class="MasterDetailLearing.MainPage">
    <!-- Place new controls here -->
    <Label Text="Welcome to Xamarin.Forms!" HorizontalOptions="Center" VerticalOptions="CenterAndExpand" />
    <MasterDetailPage.Master>
        <ContentPage Padding="10" BackgroundColor="Gray" Title="Master">
            <ContentPage.Content>
                <StackLayout Margin="5,30,5,5">
                    <Label Text="Master Page"></Label>
                </StackLayout>
            </ContentPage.Content>                
        </ContentPage>
    </MasterDetailPage.Master>

    <MasterDetailPage.Detail>
        <ContentPage Padding="10">
            <ContentPage.Content>
                <StackLayout Margin="5,30,5,5">
                    <Label Text="Detail Page"></Label>
                </StackLayout>
            </ContentPage.Content>                
        </ContentPage>
    </MasterDetailPage.Detail>

</MasterDetailPage>
1
Remove the label from top of the MasterDetailPage.Master and then see.Wasif Mahmood Mustafa
I would suggest you check my answer out here:stackoverflow.com/a/49175351/7462031FreakyAli

1 Answers

2
votes

a MasterDetail page only has Master and Detail children. You cannot include any other content as a direct child. So your Label needs to be in either the Master or the Detail, it cannot be a direct child of the page.