我正在尝试从我的手机库中添加图片,但继续获取System.Reference,我想在按下按钮时从手机库中上传图片,并在DependencyService上提供nullReferenceException。
我的页面:
InitializeComponent();
Device.OnPlatform(
Android: () => {
new Thickness(0, 20, 0, 0);
}
);
Image image = new Image();
Button addImage = new Button { Text = "Select Image" };
addImage.Clicked += (sender, args) =>
{
IGalleryImageService galleryService = DependencyService.Get<IGalleryImageService>();
galleryService.ImageSelected += (o, imageSourceEventArgs) => image.Source = imageSourceEventArgs.ImageSource;
galleryService.SelectImage();
};
this.Content = new StackLayout
{
Children =
{
image,
addImage
}
};
答案 0 :(得分:3)
您可能忘记通过添加正确的属性来导出实现。
您是否在GalleryImageService_Android.cs
文件中的命名空间声明上方有这个?
[assembly: Xamarin.Forms.Dependency (typeof (GalleryImageService_Android))]