I was looking at various posts trying to figure out what was wrong with my problem. Basically, I have an Image tag on my user control, and a Source that I would like to bind to a URL. However, this will not work. I tried using a ValueConverter that returns BitmapImage(new Uri((string)value)); but that will not work. The only thing I managed to get is that you cannot bind to the URL and that you need to upload the image that you want to bind. I do not want to upload all the images. Is there any work to achieve this without having to download the image locally. I thought the ValueConverter method would be the best by returning BitmapImage. Please, help?
public class MyViewModel { private string _posterUrl; public string PosterUrl { get {
This is my ValueConverter:
public class BitmapImageConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if(value is string) return new BitmapImage(new Uri((string)value, UriKind.RelativeOrAbsolute)); if(value is Uri) return new BitmapImage((Uri)value); throw new NotSupportedException(); } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotSupportedException(); } }
This is my XAML:
<Image Source="{Binding PosterUrl, Converter={StaticResource bitmapImageConverter}}" Width="100" Height="100" />
So, this is related to the PosterUrl property, which contains imageurl, and it is converted to bitmapimage. Any ideas?
source share