我想第一次使用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="">
感謝您的答覆,但它幾乎一樣解決方案整個觀點是僅將圖像作爲便攜式部件中的嵌入式資源,而不是每個平臺,這對背景圖像來說似乎是不可能的。 –