firebase上传图片方法报错

Error in the method for uploading an image with firebase

我在 Firebase 数据库中上传图片时遇到问题。

这是我的视图 xaml 名为:InitialPage

      <StackLayout Grid.Row="0">
            <Image Source="{Binding Icon}"/>

            <Button Text="Add Image"
                    Command="{Binding ImageDataCommand}"/>
        </StackLayout>

我有一个名为 ImageDataCommand 的按钮,当我 select 在 phone 图库中搜索图像时,在

中显示错误

Icon.Source

        private string _icon;
        public string Icon
        {
            get { return _icon; }
            set
            {
                _icon = value;
                RaisePropertyChanged();
            }
        }

        public ICommand ImageDataCommand => new Command(async (s) => await InsertImage(s));

        private async Task InsertImage(object s)
        {
            await CrossMedia.Current.Initialize();
            try
            {
                file = await CrossMedia.Current.PickPhotoAsync(new PickMediaOptions()
                {
                    PhotoSize = PhotoSize.Medium
                });
                if (file == null)
                    return;

                Icon.Source = ImageSource.FromStream(() =>
                {
                   var imageStream = file.GetStream();
                    return imageStream;
                });

            }
            catch (Exception ex)
            {

                Debug.WriteLine(ex);
            }
        }

我正在使用 FreshMvvm,我看到一种方法是使用 x:name,但在我的 InitPageModel 中未显示。

我开始使用 Freshmvvm 来避免将代码放入 类 或视图的 .cs 文件中。

问候

  1. Iconstring 更改为 ImageSource
private ImageSource _icon;
public ImageSource Icon
{
    get { return _icon; }
    set
    {
       _icon = value;
       RaisePropertyChanged();
   }
}
  1. 从图库获取图片后直接设置Icon
Icon = ImageSource.FromStream(() =>
{
    var imageStream = file.GetStream();
    return imageStream;
});