0

Hi I need bind images to listbox but when I try it I get FILE NOT FOUND but file is stored in application package in folder layoutGraphics. I try put files to default folder but I get same result anyone know what is bad?

var file = await Windows.Storage.ApplicationData.Current.LocalFolder.GetFileAsync("ms-appx:///layoutGraphics/offline.png");
        var fileStream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);
        var img = new BitmapImage();
        img.SetSource(fileStream);
        ImgSource = img;

// property

private BitmapImage _imgSource;
    public BitmapImage ImgSource
    {
        get { return _imgSource; }
        set
        {
            _imgSource = value;
            OnPropertyChanged("MyDatasMessagesUserList");
        }
    }

Or anyone know better solution how I can bind imagess from app folder to my listbox with datatemplate?

4

1 回答 1

1

Windows.Storage.ApplicationData.Current.LocalFolder 正在从应用程序存储而不是包中检索文件。对于包文件夹,您需要使用 Windows.ApplicationModel.Package.Current.InstalledLocation。此外,GetFileAsync 仅采用文件名而不是完整路径。这是完成您想要的代码的代码:

var layoutGraphiceFolder = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFolderAsync("layoutGraphics")
var file=await layoutGraphiceFolder.GetFileAsync("offline.png");

使用完整路径的另一种方法是:

var file=await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///layoutGraphics/offline.png"));
于 2013-09-11T14:57:26.350 回答