首页 > 解决方案 > Background Image XAML

问题描述

I am trying to incorporate a background image into my App using Xaml. I have tried various different methods but none seem to working. My code at the minute is

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         xmlns:local="clr-namespace:Cabiee;assembly=Cabiee"
         BackgroundImage="CabieBackground.jpg"
         x:Class="Cabiee.Login">

    <ContentPage.Content>

    <StackLayout VerticalOptions="CenterAndExpand" HeightRequest="500">


        <Entry 
            x:Name="usernameEntry" 
            Placeholder="Email"/>
        <Entry 
            x:Name="passwordEntry"
            IsPassword="true" 
            Placeholder="*********"
            Completed="PasswordEntry_Completed"/>

        <StackLayout Orientation="Horizontal">
            <Button 
                x:Name="BtnCustomer"
                Text="Customer"
                HorizontalOptions="FillAndExpand"
                VerticalOptions="FillAndExpand"
                FontSize="30"
                Clicked="BtnCustomer_Clicked"/>
            <Button
                x:Name="BtnDriver"
                Text="Driver"
                HorizontalOptions="FillAndExpand"
                VerticalOptions="FillAndExpand"
                FontSize="30"
                Clicked="BtnDriver_Clicked"/>
        </StackLayout>
        <RelativeLayout HorizontalOptions="CenterAndExpand" >
            <Button  
                x:Name="BtnRegister"
                WidthRequest="300"
                Text="Register"
                FontSize="30"
                Clicked="BtnRegister_Clicked"
            />

        </RelativeLayout>


    </StackLayout>


</ContentPage.Content>

And this what my solution explorer looks like: https://gyazo.com/0af186bbca7e8456dfb1e7b1bafcb7ad

I have CabieBackground.jpg in my Resources folder so that is displays on android but when i run the code nothing appears on the screen, it just blank

The background image was made in photoshop, the dimensions are: 640px by 1136 px with a resolution of 600 pixels/inch

标签: xamlxamarin.forms

解决方案


您需要将图像放在可绘制文件夹中。https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/images?tabs=windows#local-images

正如评论中所说,您还应该确保图像具有正确的属性,因为复制和粘贴会产生错误的属性。


推荐阅读