简体   繁体   English

如何在 MasterDetailPage 菜单中设置背景图片

[英]How to set Background image in MasterDetailPage menu

How to set Background image in MasterDetailPage menu without RelativeLayout and AbsoluteLayout .如何在没有RelativeLayoutAbsoluteLayout的情况下在 MasterDetailPage 菜单中设置背景图像。 I also tried with Grid and AbsoluteLayout but it's not working.我也尝试使用 Grid 和 AbsoluteLayout,但它不起作用。 any solution for this problem?这个问题有什么解决办法吗?

BackgroundImageSource="background.png" is also not working. BackgroundImageSource="background.png"也不起作用。

My Xaml:我的 Xaml:

<MasterDetailPage.Master>
    <ContentPage Title="Menu" BackgroundColor="White"
                 Icon="hamburger.png">
        <StackLayout Orientation="Vertical" >
            <StackLayout x:Name="navigationDrawerList"
                         VerticalOptions="Fill">

                <BindableLayout.ItemTemplate>
                    <DataTemplate>
                        <StackLayout>
                            <StackLayout VerticalOptions="FillAndExpand"
                                         Orientation="Horizontal"
                                         Padding="20,0,0,0"
                                         Spacing="20">

                                <Label Text="{Binding Title}"
                                       FontSize="Medium"
                                       VerticalOptions="Center"
                                       TextColor="Gray" />

                            </StackLayout>
                        </StackLayout>
                    </DataTemplate>
                </BindableLayout.ItemTemplate>

            </StackLayout>   
            <StackLayout VerticalOptions="FillAndExpand"
                         Orientation="Horizontal"
                         Padding="50,2,0,2"
                         Spacing="20">

                <Label Text="About Us"
                       FontSize="Medium"
                       VerticalOptions="Center"
                       TextColor="Gray" />
            </StackLayout>
            <StackLayout VerticalOptions="FillAndExpand"
                         Orientation="Horizontal"
                         Padding="50,2,0,2"
                         Spacing="20">

                <Label Text="FAQ"
                       FontSize="Medium"
                       VerticalOptions="Center"
                       TextColor="Gray" />

            </StackLayout>
        </StackLayout> 
    </ContentPage>
</MasterDetailPage.Master>

If you wrap your MasterDetailPage content inside a nested Grid, the Image and the Content will overlap eachother, creating the Backgound effect you are looking for如果您将 MasterDetailPage 内容包装在嵌套的 Grid 中,图像和内容将相互重叠,从而创建您正在寻找的背景效果

<MasterDetailPage.Master>
    <ContentPage Title="Menu" BackgroundColor="White"
                 Icon="hamburger.png">
        <Grid>
            <Grid VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand">
                <Image Source="background.png" Aspect="AspectFill"></Image>
            </Grid>
            <Grid>
                //Your MasterDetailPage content
            </Grid>
        </Grid>
    </ContentPage>
</MasterDetailPage.Master>

Try this out, you have to set your background color as transparent to set a background image.试试看,您必须将背景颜色设置为透明才能设置背景图像。 The trick worked for me, hope it works for you as well这个技巧对我有用,希望对你也有用

<MasterDetailPage.Master>
    <ContentPage Title="Menu"
          BackgroundColor="Transparent"
          BackgroundImage="hamburger.png">
        //Your xaml
    </ContentPage>
</MasterDetailPage.Master>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM