Xamarin形成嵌入资源图像作为XAML中contentpage的背景



我是第一次尝试Xamarin表格,所以这可能是一个不好的问题,请原谅我。

我有一个图像作为嵌入资源:截屏我可以将该图像用作XAML中的背景图像吗?如何

提前谢谢大家。

更新,如下所示:https://developer.xamarin.com/guides/xamarin-forms/working-with/images/#embedded_images:

  1. 我将自定义XAML标记扩展扩展到主页CS:
[Xamarin.Forms.ContentProperty("Source")]
public class ImageResourceExtension : Xamarin.Forms.Xaml.IMarkupExtension
{
    public string Source { get; set; }
    public object ProvideValue(IServiceProvider serviceProvider)
    {
        if (Source == null)
        {
            return null;
        }
        // Do your translation lookup here, using whatever method you require
        var imageSource = Xamarin.Forms.ImageSource.FromResource(Source);
        return imageSource;
    }
}
  1. 我现在可以使用这样的图像:
  <StackLayout VerticalOptions="Center" HorizontalOptions="Center">
    <!-- use a custom Markup Extension -->
    <Image Source="{local:ImageResource App2.images.back_01.png}" />
  </StackLayout>
  1. 仍然我无法回答的原始问题,如何使其在
  2. 中使其背景
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:App2;assembly=App2"
             x:Class="App2.MainPage"
             BackgroundImage="">

似乎在便携式中制作图像嵌入资源,用于所有图像用法 backgroundImage。
要用于背景图像,图像必须 都嵌入到每个平台资源中(必须选择正确的每个平台构建操作)。
然后,对于背景图像,可以反驳这样做:" folder_name/file_name.png"因此,必须一次完成几次(与其他图像用法相反)。


以上对我有用的解决方案。
如果有人知道如何在没有冗余措施的情况下执行此操作,请执行发布。

将图像放在文件夹中:

Android进入 Resources/drawable

对于iOS进入Resources

然后尝试

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:App2;assembly=App2"
             x:Class="App2.MainPage"
             BackgroundImage="back01.png">

最新更新