Xaml Xamarin形成背景中的第二个图像

Xaml Xamarin形成背景中的第二个图像,xaml,layout,xamarin.forms,Xaml,Layout,Xamarin.forms,我想实现类似的目标: 我已经在XAML中为渐变背景设置了BackgroundImage=xxx。但是我想在背景和粉红色的堆叠布局之间添加另一张图片(比如邮箱)。所以当我滚动图片时,图片不会移动(就像渐变背景一样),其余的会移动 尝试过之后,它适用于后台,但由于我在xaml中定义了所有元素,而不是代码隐藏,所以它只显示后台 基本上,我希望将上面的解决方案和我的元素混合在XAML中。 类似于此(这是不可能的):Content+=mainLayout 我复制了一些类似的东西,但如果我滚动,图片会随着

我想实现类似的目标:

我已经在XAML中为渐变背景设置了BackgroundImage=xxx。但是我想在背景和粉红色的堆叠布局之间添加另一张图片(比如邮箱)。所以当我滚动图片时,图片不会移动(就像渐变背景一样),其余的会移动

尝试过之后,它适用于后台,但由于我在xaml中定义了所有元素,而不是代码隐藏,所以它只显示后台

基本上,我希望将上面的解决方案和我的元素混合在XAML中。 类似于此(这是不可能的):
Content+=mainLayout

我复制了一些类似的东西,但如果我滚动,图片会随着其他部分一起移动。试图将图片放在相对布局中,但没有效果

XAML:

<ScrollView>
    <StackLayout Spacing="0" Padding="0">
        <Image Source="mailbox.png" Scale="1.3"/>

        <StackLayout Padding="15">
            <StackLayout Margin="5" BackgroundColor="#E6fa175b">
                <Label Text="CONTACT" TextColor="White" VerticalOptions="CenterAndExpand" HorizontalOptions="CenterAndExpand" FontSize="Large" Margin="10"/>
                <Entry x:Name="mail_Name" Placeholder="Prénom Nom" PlaceholderColor="White" WidthRequest="150" Margin="10"/>
            </StackLayout>
            <StackLayout Margin="5" BackgroundColor="#E6fa175b" >
                <Entry x:Name="mail_Email" Placeholder="Email" PlaceholderColor="White"  WidthRequest="150" Margin="10"/>
            </StackLayout>
            <StackLayout Margin="5" BackgroundColor="#E6fa175b">
                <Label Text="Votre message" FontSize="Medium" TextColor="White" Margin="10,3" HeightRequest="30" />
                <Editor x:Name="mail_Msg" WidthRequest="150" HeightRequest="80" Margin="10"/>
            </StackLayout>
        </StackLayout>
        <Button x:Name="btn_send_mail" Clicked="Click_Send" HorizontalOptions="FillAndExpand" Text="Envoyer" BackgroundColor="LightSteelBlue"/>
    </StackLayout>
</ScrollView>

一些Xamarin.Forms的内置布局,如
网格
绝对布局
,以及
相对布局
允许重叠视图。只要使用其中一个,你就能做到

在您的情况下,我相信设置图像的滚动视图就足够了

像这样:

<Grid>
    <Image Grid.Column="0" Grid.Row="0"
           HorizontalOptions= "CenterAndExpand"
           VerticalOptions="Start"
           Source="mailbox.png" Scale="1.3"/>

    <ScrollView Grid.Column="0" Grid.Row="0">
        <StackLayout Spacing="0" 
                     Padding="0">
            <StackLayout Padding="15">
                <StackLayout Margin="5" 
                             BackgroundColor="#E6fa175b">
                    <Label Text="CONTACT" 
                           TextColor="White" 
                           VerticalOptions="CenterAndExpand" 
                           HorizontalOptions="CenterAndExpand" 
                           FontSize="Large" 
                           Margin="10"/>
                    <Entry x:Name="mail_Name" 
                           Placeholder="Prénom Nom" 
                           PlaceholderColor="White" 
                           WidthRequest="150" 
                           Margin="10"/>
                </StackLayout>
                <StackLayout Margin="5" 
                             BackgroundColor="#E6fa175b" >
                    <Entry x:Name="mail_Email" 
                           Placeholder="Email" 
                           PlaceholderColor="White"  
                           WidthRequest="150" 
                           Margin="10"/>
                </StackLayout>
                <StackLayout Margin="5" 
                             BackgroundColor="#E6fa175b">
                    <Label Text="Votre message" 
                           FontSize="Medium" 
                           TextColor="White" 
                           Margin="10,3" 
                           HeightRequest="30" />
                    <Editor x:Name="mail_Msg" 
                            WidthRequest="150" 
                            HeightRequest="80" 
                            Margin="10"/>
                </StackLayout>
            </StackLayout>
            <Button x:Name="btn_send_mail" 
                    Clicked="Click_Send" 
                    HorizontalOptions="FillAndExpand" 
                    Text="Envoyer" 
                    BackgroundColor="LightSteelBlue"/>
        </StackLayout>
    </ScrollView>
</Grid>


我希望它能有所帮助。

请将相关代码与您的问题分享,或与其他人分享。因此,我们将能够给你一个客观和完整的答案。我添加了我在这个时候写的代码,idk,如果它是你的意思,但它将说明更可怕的,这是有效的!从未想过这样使用网格。@Grounch极好。您也可以使用
AbsoluteLayout
RelativeLayout
。一般规则是,
XAML
上声明的最后一项是布局视图的最上面。我认为网格更简单