0

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>
Pang
  • 9,564
  • 146
  • 81
  • 122
Nation
  • 496
  • 2
  • 5
  • 22

1 Answers1

2

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.

Jason
  • 86,222
  • 15
  • 131
  • 146
  • Thanks, this worked. I was following an old Xamarin tutorial and they had it. I guess the older version of Xamarin allowed it, because it worked for the tutor in the video. – Nation Oct 12 '18 at 16:02