WPF has built-in converters for certain types. If you bind the Image Source property to a string or Uri value, under the hood, WPF will use ImageSourceConverter to convert the value to ImageSource .
So,
<Image Source="{Binding ImageSource}"/>
will work if the ImageSource property is a string representation of a valid URI for the image.
You can, of course, collapse your own binding converter:
public class ImageConverter : IValueConverter { public object Convert( object value, Type targetType, object parameter, CultureInfo culture) { return new BitmapImage(new Uri(value.ToString())); } public object ConvertBack( object value, Type targetType, object parameter, CultureInfo culture) { throw new NotSupportedException(); } }
and use it as follows:
<Image Source="{Binding ImageSource, Converter={StaticResource ImageConverter}}"/>
Brian Leahy Aug 21 '08 at 18:38 2008-08-21 18:38
source share