【问题标题】:The property 'Content' is set more than once - XAML属性“内容”设置不止一次 - XAML
【发布时间】:2020-09-27 23:06:11
【问题描述】:

每次我尝试在我的主页显示的“属性'内容'设置不止一次”中实现<maps:Map IsShowingUser="True" x:Name="Mapa" />。每次我放在这个地方都会给我'属性'内容'设置不止一次'。

如果有人可以简单地解释 Content 属性的设置位置,那将是最有帮助的。

<ContentPage xmlns:maps="clr-namespace:Xamarin.Forms.GoogleMaps;assembly=Xamarin.Forms.GoogleMaps"
             xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:d="http://xamarin.com/schemas/2014/forms/design"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             mc:Ignorable="d" 
             x:Class="Pap.MainPage">

    <maps:Map IsShowingUser="True" x:Name="Mapa" />

    <AbsoluteLayout VerticalOptions="FillAndExpand" x:Name="Main">
        
        <StackLayout AbsoluteLayout.LayoutBounds="0,0,1,1" AbsoluteLayout.LayoutFlags="All" x:Name="main" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand">
            <Image Source="C:\Users\david\Desktop\Pap\Pap\Pap.Android\Resources\drawable\User.png" Aspect="AspectFill" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"></Image>

        </StackLayout>
        <StackLayout x:Name="body" AbsoluteLayout.LayoutBounds="0,0,1,1" AbsoluteLayout.LayoutFlags="All"
   Orientation="Vertical" VerticalOptions="FillAndExpand" Spacing="0">
            <!--<StackLayout VerticalOptions="End" BackgroundColor="Red">
    <Label Text="Titulo" />
    
   </StackLayout>-->
            <StackLayout VerticalOptions="FillAndExpand">
                <Label Text="Slider-Example"  HorizontalOptions="Center" VerticalOptions="Center"/>
                <Image Source="C:\Users\david\Desktop\Pap\Pap\Pap.Android\Resources\drawable\User.png" Aspect="AspectFill"></Image>
                <StackLayout.GestureRecognizers>
                    <TapGestureRecognizer Tapped="Handle_Tapped">
                    </TapGestureRecognizer>
                </StackLayout.GestureRecognizers>
            </StackLayout>
        </StackLayout>
    </AbsoluteLayout>

</ContentPage>

【问题讨论】:

    标签: xamarin


    【解决方案1】:

    ContentPage 有一个隐含的Content 属性,可以包含一个单个 子元素。如果您想在页面上包含多个内容,则需要使用Layout 容器,例如StackLayout

    <ContentPage ... >
      <StackLayout>
        ... multiple children can go here
      </StackLayout>
    </ContentPage>
    

    如果您使用 C# 而不是 XAML,则应显式设置 Content 属性

    myPage.Content = new StackLayout{ ... };
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多