Hi guys, I already implement Xamarin.Forms.Labs into project and use the sample code to test. It doesn't show any error when i clicked the button, but it does not response anything. Please kindly help me. thank you.
*I already set the CAMERA-Permission, and the WRITE_EXTERNAL_STORAGE-Permission.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Emit;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using Xamarin.Forms.Labs;
using Xamarin.Forms.Labs.Services;
using Xamarin.Forms.Labs.Services.Media;
namespace eRestaurant.Pages
{
public class AddFoodPage : ContentPage
{
private ImageSource imageSource;
private IMediaPicker mediaPicker;
private Image img;
private string status;
public AddFoodPage()
{
this.Title = "Camera Test";
NavigationPage.SetHasNavigationBar(this, false);
img = new Image() { HeightRequest = 300, WidthRequest = 300, BackgroundColor = Color.FromHex("#D6D6D2"), Aspect = Aspect.AspectFit };
var addPictureButton = new Button()
{
Text = "Select Picture",
Command = new Command(async () => { await SelectPicture();})
};
StackLayout stack = new StackLayout();
stack.VerticalOptions = LayoutOptions.FillAndExpand;
stack.Children.Add(new BoxView { Color = Color.Transparent, HeightRequest = 20 });
stack.Children.Add(addPictureButton);
stack.Children.Add(img);
ScrollView scrollview = new ScrollView
{
Orientation = ScrollOrientation.Vertical,
VerticalOptions = LayoutOptions.FillAndExpand,
Content = stack
};
this.Content = new StackLayout
{
Children = { scrollview }
};
}
private async Task SelectPicture()
{
mediaPicker = DependencyService.Get<IMediaPicker>();
imageSource = null;
try
{
var mediaFile = await mediaPicker.SelectPhotoAsync(new CameraMediaStorageOptions
{
DefaultCamera = CameraDevice.Front,
MaxPixelDimension = 400
});
imageSource = ImageSource.FromStream(() => mediaFile.Source);
img.Source = imageSource;
}
catch (System.Exception ex)
{
this.status = ex.Message;
}
}
}