我想将相机/ 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中进行更改)
答案 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
时需要帮助,请与我们联系。