【发布时间】:2019-03-22 15:07:28
【问题描述】:
我已经尝试了 2 天,无法在我的 Xaml 上显示来自 MVVM Xamarin 表单的图像。如果有人可以帮助我解决这个问题,我将不胜感激。 这是我的代码:
XAML
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Image Source="{Binding GetImageSource}" Grid.Column="0" Grid.Row="0" HorizontalOptions="Center" />
<Image Source="camera.png" HorizontalOptions="Center" Grid.Column="0" Grid.Row="1">
<Image.GestureRecognizers>
<TapGestureRecognizer Command="{Binding TakePhoto}" />
</Image.GestureRecognizers>
</Image>
</Grid>
我的视图模型
使用 Plugin.Media(从图库中选择图片)
我用过 TapGestureRecognizer
哪个工作正常
private ImageSource imageSource { get; set; }
public ImageSource GetImageSource
{
get { return imageSource; }
set
{
imageSource = value;
}
}
if (!CrossMedia.Current.IsPickPhotoSupported)
{
var message = "Picking image is not supported";
DependencyService.Get<IMessage>().ShortAlert(message);
return;
}
var files = await CrossMedia.Current.PickPhotoAsync();
if (files == null)
return;
GetImageSource = ImageSource.FromStream(() =>
{
var stream = files.GetStream();
return stream;
});
var ms = new MemoryStream();
files.GetStream().CopyTo(ms);
files.Dispose();
imgAsBytes = ms.ToArray();
ms.Dispose();
我设法以字节为单位获取图像,这很好,但我无法显示图像。 提前感谢您的支持。
【问题讨论】:
-
你的虚拟机是否实现了 INotifyPropertyChanged?
标签: xaml xamarin mvvm xamarin.forms xamarin.android