Reputation: 87
I am developing an application in XAML/C#, where path of the image in stored in the list. The path contains spaces because it is the path of the file with in the computer C Drive. I am unable to bind it. I tried using
<Image Name="ImageOffer">
<Image.Source>
<BitmapImage UriSource="{Binding ImagePath}" />
</Image.Source>
</Image>
Can anyone tell me the way of binding images from outside folder of application in XAML. Thanks
Upvotes: 0
Views: 2955
Reputation: 15296
You can't bind image from ANY location. WinRT has sandboxed environment, so you can bind image from known locations only like libraries, local folder, asset folder.
public class ViewModel
{
public string ImagePath { get; set; }
public ImageSource ImgSource
{
get
{
return new BitmapImage(new Uri("ms-appx:///" + this.ImagePath));
}
}
}
<Image Source="{Binding ImgSource}" />
Please note to access files stored inside the application package use the ms-appx: scheme & to access files stored in the application state, use the ms-appdata: scheme. Application state may be stored in a local folder, a roaming folder, or a temp folder.
Some more resources.
How to load file resources (Windows Store apps using C#/VB/C++ and XAML)
Handling binding between WinRT Image control and ViewModel for local file system images
Upvotes: 3