微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

多次设置属性“内容”-XAML

如何解决多次设置属性“内容”-XAML

每次我尝试在mainPage节目的“属性'Content'设置不止一次”中实现<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,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,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>

解决方法

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

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

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

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。