Xamarin表单中的图片作为背景未显示

时间:2019-04-07 18:40:53

标签: c# xaml xamarin xamarin.forms

我想在Xamarin Forms Android应用中将图片用作背景。该图像存储在可绘制文件夹中。当我在智能手机上调试应用程序时,不会显示该图像。下面是代码。谢谢

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:XamarinTest"
             x:Class="XamarinTest.MainPage"
             BackgroundImage = "BGImage.jpeg">

    <StackLayout>
        <!-- Place new controls here -->
        <Label Text="Welcome to Xamarin.Forms!" 
           HorizontalOptions="Center"
           VerticalOptions="CenterAndExpand" />
    </StackLayout>
</ContentPage>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;

namespace XamarinTest
{
    public partial class MainPage : ContentPage
    {
        public MainPage()
        {
            InitializeComponent();


        }
    }
}

2 个答案:

答案 0 :(得分:0)

我想您只是将其存储在文件夹中,而没有将其添加到项目中。

您应该右键单击resource-> drawable文件夹-> add->添加文件以添加图像文件。

答案 1 :(得分:0)

检查图像存储位置:

对于Android,iOS-资源文件夹;

对于Windows Phone,为Win / UWP-“资产”文件夹;

还要选中“生成操作”(对于Android,应为AndroidResource,对于iOS,应为BundleResource),此外(如果仍未显示),“复制到Ouput目录”应为“如果更新则复制” 。 enter image description here

相关问题