【问题标题】:Picture as background in Xamarin Forms is not displayed在 Xamarin Forms 中作为背景的图片不显示
【发布时间】:2019-04-08 15:41:56
【问题描述】:

我想在我的 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();


        }
    }
}

【问题讨论】:

  • 图片的构建动作属性是什么?
  • 晕haldo,属性是嵌入式资源。非常感谢
  • 好的,没关系。文件名是什么?它是否包含任何- 破折号/连字符?如果确实包含-,请尝试用_ 替换,看看是否有效。
  • Helo haldo 这个名字没有任何 - 或其他字符。在 Android 模拟器中显示图像,但在我的智能手机中没有
  • 你能用Android resource代替Embedded resource吗?这是安卓还是iOS?

标签: c# xaml xamarin xamarin.forms


【解决方案1】:

我猜你只是将它存储在文件夹中而不是将它添加到项目中。

你应该右键资源->drawable文件夹-->添加-->添加文件来添加图片文件。

【讨论】:

    【解决方案2】:

    检查您将图像存储在哪里:

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

    对于 Windows Phone,Win/UWP - Assets 文件夹;

    还要检查“构建操作”(Android 应为AndroidResource,iOS 应为BundleResource),另外(如果仍未显示)“复制到输出目录”应为“如果更新则复制”。

    【讨论】:

      猜你喜欢
      • 2020-09-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多