これを行う1つの方法は、Prism.IPageDialogService
のActionSheetを表示してユーザーに選択肢を与えることです。あなたも、クロスプラットフォームソリューションを持っているためにこのような何かを行うことができます。PickPhoto()
の
private async void TakePhoto()
{
await CrossMedia.Current.Initialize();
if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported)
{
await _dialogService.DisplayAlertAsync("Warning", "Camera not available", "OK");
return;
}
_mediaFile = await CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions
{
SaveToAlbum = true,
Directory = "Sample",
Name = "sample" + DateTime.Now.ToLocalTime().ToString("yyyyMMddHHmmss") + ".jpg"
});
if (_mediaFile == null)
{
return;
}
ImageButtonAddGroup = _mediaFile.Path;
}
実装:TakePhoto()
の
private async void AddImage() // This is your method for your button
{
string chosen = await _dialogService.DisplayActionSheetAsync("Which source do you want to use?", "Cancel", null, "Camera", "Galery");
if (chosen == "Camera")
{
TakePhoto();
}
else if (chosen == "Galery")
{
PickPhoto();
}
}
実装
private async void PickPhoto()
{
await CrossMedia.Current.Initialize();
if (!CrossMedia.Current.IsPickPhotoSupported)
{
await _dialogService.DisplayAlertAsync("Warning", "Camera not available", "OK");
return;
}
_mediaFile = await CrossMedia.Current.PickPhotoAsync();
if (_mediaFile == null)
{
return;
}
ImageButtonAddGroup = _mediaFile.Path;
}
をあなたの代わりに2つのボタンが必要な場合1つのうち、Prism.IPageDialogService
は不要で、メソッドTakePhoto()
とPickPhoto()
を2つのdにバインドすることができます異なるボタン。