C# Xamarin在XAML中形成嵌入的资源图像作为ContentPage的背景
我是第一次尝试Xamarin表格,所以这可能是一个写得不好的问题,如果是,请原谅 我有一个嵌入资源的图像: 我可以在XAML中将该图像用作ContentPage的背景图像吗?怎么 提前谢谢大家 更新建议如下: :C# Xamarin在XAML中形成嵌入的资源图像作为ContentPage的背景,c#,xaml,xamarin,xamarin.forms,C#,Xaml,Xamarin,Xamarin.forms,我是第一次尝试Xamarin表格,所以这可能是一个写得不好的问题,如果是,请原谅 我有一个嵌入资源的图像: 我可以在XAML中将该图像用作ContentPage的背景图像吗?怎么 提前谢谢大家 更新建议如下: : 我将自定义xaml标记扩展添加到主页cs: 我现在可以像这样使用图像: 仍然是我无法回答的原始问题,如何使其成为背景 似乎使图像嵌入资源仅可移植,适用于除BackgroundImage之外的所有图像用途。 要用于背景图像,图像还必须嵌入每个平台资源中(必须选择正确的每个平台构建
似乎使图像嵌入资源仅可移植,适用于除BackgroundImage之外的所有图像用途。
要用于背景图像,图像还必须嵌入每个平台资源中(必须选择正确的每个平台构建操作)。
然后,对于背景图像,可以这样判断:“folder\u name/file\u name.png” 因此,它必须执行多次,而不是一次(与其他图像用法相反)。
以上是我的一个解决方案
如果有人知道如何在没有冗余操作的情况下执行此操作,请发布。将图像放入文件夹: 对于
Android
到Resources/drawable
对于iOS
到资源
然后试试看
<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">
感谢您的回复,但与下面的解决方案几乎相同。整个要点是仅将图像用作便携部件中的嵌入式资源,而不是每个平台,这对于背景图像来说似乎是不可能的。我认为您需要说local:ImageResourceExtension
,而不是XAML代码中的local:ImageResource
,正如我所观察到的,BackgroundImage仅适用于iOS
<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="">
<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">