Xamarin将图像导入到新页面

时间:2016-07-18 19:40:49

标签: c# xamarin.android xamarin.forms

我想将相机/ Gallary图像导入页面,而不是导入App()页面,功能ShouldTakePicture()不起作用,任何人都可以提供我可以导入的示例代码图像到另一个页面并显示在列表视图中?

此导入图片是通过链接http://xforms-kickstarter.com/#camera

中的代码完成的

但是,当在另一个页面中执行时,MainActivity会抛出错误

Severity Code Description Project File Line Suppression State Error CS1503 Argument 1: cannot convert from 'Gallary2.Injury' to 'Xamarin.Forms.Application' Gallary2.Droid C:\Users\haris\Documents\Visual Studio 2015\Projects\Gallary2\Gallary2\Gallary2.Droid\MainActivity.cs 32 Active

任何人都可以帮我处理Xamarin Forms中的图像导入演示项目吗? (只有c#请,我们不会在XAML中进行更改)

1 个答案:

答案 0 :(得分:0)

听起来您创建了一个新页面,在该新页面中,您创建了ShouldTakePicture类型Action的属性。代码现在失败的原因是因为iOS和Android项目中的这一行:

(Xamarin.Forms.Application.Current as App).ShouldTakePicture += () => {

该行希望ShouldTakePicture属性位于您的App课程中,但已移至新页面。

要解决此问题,您可以将该属性移回App课程,然后通过调用Command = new Command(o => App.ShouldTakePicture()),从新页面引用该属性。

更好的解决方法是使用Xamarin的DependencyService,有关的信息是here。如果您在设置DependencyService时需要帮助,请与我们联系。