我想第一次使用Xamarin表单,所以这可能是一个写得不好的问题,请原谅我,如果是的话。Xamarin形式为XAML中ContentPage的背景嵌入资源图像
我有一张照片作为嵌入式资源: screenshot 我是否可以使用图像的BackgroundImage在XAML,为ContentPage?如何
谢谢大家提前。
UPDATE,作为这里提出: https://developer.xamarin.com/guides/xamarin-forms/working-with/images/#Embedded_Images:
- 我添加的自定义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; } }
- 我现在可以使用像这样的图像:
- 还是原来的问题我不能回答,如何使它背景
<StackLayout VerticalOptions="Center" HorizontalOptions="Center"> <!-- use a custom Markup Extension --> <Image Source="{local:ImageResource App2.images.back_01.png}" /> </StackLayout>
<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="">
感谢您的答复,但它几乎一样解决方案整个观点是仅将图像作为便携式部件中的嵌入式资源,而不是每个平台,这对背景图像来说似乎是不可能的。 –