windows-store-apps - MvvmCross:NotImplementedException 调用 IMvxFileStore 的 EnsureFolderExists 方法

标签 windows-store-apps mvvmcross

我正在使用 MvvmCross 框架开发我的第一个 Windows 应用商店应用程序,但我在图像管理方面遇到问题。特别是,我的 PCL 项目中有以下简单的 ViewModel,以及一个带有与 AddPictureCommand 绑定(bind)的按钮的 Store 项目。

    public class FirstViewModel : MvxViewModel
{

    IMvxPictureChooserTask _pictureChooserTask;
    IMvxFileStore _fileStore;

    public FirstViewModel(IMvxPictureChooserTask pictureChooserTask, IMvxFileStore fileStore)
    {
        _pictureChooserTask = pictureChooserTask;
        _fileStore = fileStore;
    }

    private byte[] _pictureBytes;
    public byte[] PictureBytes
    {
        get { return _pictureBytes; }
        set
        {
            if (_pictureBytes == value) return;
            _pictureBytes = value;
            RaisePropertyChanged(() => PictureBytes);
        }
    }

    public ICommand AddPictureCommand
    {
        get { return new MvxCommand(() => 
        {
            _pictureChooserTask.ChoosePictureFromLibrary(400, 95, pictureAvailable, () => { });
        }); }
    }

    private void pictureAvailable(Stream stream)
    {
        MemoryStream memoryStream = new MemoryStream();
        stream.CopyTo(memoryStream);
        PictureBytes = memoryStream.ToArray();

        GenerateImagePath();
    }

    private string GenerateImagePath()
    {
        if (PictureBytes == null) return null;
        var RandomFileName = "Image" + Guid.NewGuid().ToString("N") + ".jpg";
        _fileStore.EnsureFolderExists("Images");
        var path = _fileStore.PathCombine("Images", RandomFileName);
        _fileStore.WriteFile(path, PictureBytes);

        return path;
    }
}

问题在于方法 _fileStore.EnsureFolderExists("Images"); 给我一个“NotImplementedException”,其中包含消息:“需要实现这个 - 从 StorageFolder API 来看似乎并不明显”。 有人以前看过吗? 谢谢

最佳答案

这个未实现的异常记录在 wiki 中 - 请参阅 https://github.com/MvvmCross/MvvmCross/wiki/MvvmCross-plugins#File

如果需要的话,实现这些缺失的方法应该相当简单。事实上,我知道至少有 2 位用户已经实现了这些 - 但遗憾的是他们还没有做出贡献。

要实现它们,只需

有关使用 ioc 的更多信息,请参阅 https://github.com/MvvmCross/MvvmCross/wiki/Service-Location-and-Inversion-of-Control

有关自定义设置顺序的更多信息,请参阅 https://github.com/MvvmCross/MvvmCross/wiki/Customising-using-App-and-Setup

关于windows-store-apps - MvvmCross:NotImplementedException 调用 IMvxFileStore 的 EnsureFolderExists 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19890756/

相关文章:

ios - MvvmCross - TableViewCell 与值转换器的延迟绑定(bind) - DataContext 设置不正确?

windows-phone-7 - 我可以在可移植类库中使用 "dynamic"关键字吗?

c# - C#中的 bool 运算

c# - 应用程序调用了为不同线程编码的接口(interface) - Windows 应用商店应用程序

c# - 从 MainPage 访问 UserControl 中 ItemsSource 内的 Canvas

c# - 使用 MVVMCross 的属性条件绑定(bind)

c# - 如何将 Android RadioGroup 的 RadioButton 与 MVVMCross 绑定(bind)

android - 通过 bool 值设置 LinearLayout 背景色

c# - 保存当前视频帧-Windows Store应用

c# - 是否真的应该为任何异步操作添加延迟?