Button内容错误中缺少ContentPropertyAttribute

时间:2018-02-15 13:08:53

标签: c# xaml xamarin

我是.net开发世界的新手,我在这里可能有一个错误的错误,但我不知道怎么做。错误是:位置15:16:“无法设置按钮的内容,因为它没有ContentPropertyAttribute”。所以这是我的代码:

`

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         x:Class="PlantsApp.HomePage"
         Title="Home">

<ContentPage.Content>

<ScrollView>

  <StackLayout Spacing="0" Padding="0" BackgroundColor="White">
    <Image x:Name="plantsOk" Source="Resources/PlantsOk.png" HorizontalOptions="Center" VerticalOptions="Start" />
    <Label x:Name="plantsOkText" Text="Plants are doing well!" TextColor="#005329" HorizontalOptions="Center"/>
    <StackLayout BackgroundColor="White" Padding="10">
      <StackLayout HorizontalOptions="Start" VerticalOptions="StartAndExpand">
        <Button x:Name="myPlants"  WidthRequest="100" HeightRequest="100" HorizontalOptions="StartAndExpand" >
          <StackLayout Orientation="Vertical">
            <Image Source="MyPlants.png"></Image>
            <Label >My plants</Label>
          </StackLayout>
        </Button>

        <Button WidthRequest="100" HeightRequest="100" HorizontalOptions="EndAndExpand" >
          <StackLayout Orientation="Vertical">
            <Image Source="ToDo.png"></Image>
            <Label >To Dos</Label>
          </StackLayout>

        </Button>
        <!--
          <Label>To Do</Label>-->
      </StackLayout>
      <StackLayout VerticalOptions="EndAndExpand">
        <Button x:Name="history" WidthRequest="100" HeightRequest="100" HorizontalOptions="StartAndExpand" >
          <StackLayout Orientation="Vertical">
            <Image Source="History.png"  ></Image>
            <Label >History</Label>
          </StackLayout>

        </Button>
        <!--
          <Label>History</Label>-->

        <Button WidthRequest="100" HeightRequest="100" HorizontalOptions="EndAndExpand" >
          <StackLayout Orientation="Vertical">
            <Image Source="PlantsBook.png"></Image>
            <Label >Plants Book</Label>
          </StackLayout>

        </Button>
        <!--<Image Source="Resources/PlantsBook.png"></Image>
          <Label>Plants book</Label>-->
      </StackLayout>
    </StackLayout>
  </StackLayout>
</ScrollView>
</ContentPage.Content>
</ContentPage>`

1 个答案:

答案 0 :(得分:0)

Button不是容器,因此不能包含StackLayoutButton具有明确的属性,可用于设置TextImage

<Button WidthRequest="100" HeightRequest="100" HorizontalOptions="EndAndExpand" Image="ToDo.png" Text="To Dos" />