【发布时间】:2016-08-22 16:50:43
【问题描述】:
我有一个在运行时创建的图像文件。
我想将其设置为 ContentPage 的 backgroundImage(在 android 项目中)
我尝试将文件的路径设置为 BackgroundImage 属性,但它不起作用。
有办法吗?
我不能把它作为资源,因为我是在运行时创建的
【问题讨论】:
标签: xamarin.forms
我有一个在运行时创建的图像文件。
我想将其设置为 ContentPage 的 backgroundImage(在 android 项目中)
我尝试将文件的路径设置为 BackgroundImage 属性,但它不起作用。
有办法吗?
我不能把它作为资源,因为我是在运行时创建的
【问题讨论】:
标签: xamarin.forms
将您的页面放入Grid,其中第一个元素是Image,然后将该图像Source 设置为您的流,例如:
Image bgImage = new Image
{
Source = ImageSource.FromStream(() => { return new MemoryStream(buffer); });
}
Grid mainGrid = new Grid
{
Children = {bgImage,yourContent}
};
yourPage.Content= mainGrid;
【讨论】:
我认为文档已经过时了。因为目标 Android 拥有不止一种资源。 作为 /drawable-hdpi /drawable-xhdpi 等等
因此,您应该为所有文件夹添加图像,因为它适用于设备。它有效。
*但我认为 Xamarin.Forms 的主要问题 因为当系统找不到特殊分辨率时,可绘制文件夹必须默认图像源必须从默认文件夹中选择... *
【讨论】: