Envoyé par
ludojojo
Peux-tu essayer ça :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| public object Convert(object value, Type targetType,
object parameter, CultureInfo culture)
{
try
{
string imageUrl = (string)value;
if(!string.IsNullOrEmpty(imageUrl))
{
imageUrl = imageUrl.split(',')[0];
}
return new BitmapImage(new Uri(imageUrl));
}
catch
{
return new BitmapImage();
}
} |
Voici mon converter :
public class ImageConverter : IValueConverter
{
public object Convert(object value, Type targetType,
object parameter, CultureInfo culture)
{
try
{
string imageUrl = (string)value;
if (!string.IsNullOrEmpty(imageUrl))
{
imageUrl = imageUrl.Split(',')[0];
}
return new BitmapImage(new Uri(imageUrl));
}
catch
{
return new BitmapImage();
}
}
public object Convert(object value, Type targetType, object parameter, string language)
{
throw new NotImplementedException();
}
public object ConvertBack(object value, Type targetType, object parameter, string language)
{
throw new NotImplementedException();
}
}
la partie xaml :
<Image x:Name="imageArticles">
<Image.Source>
<BitmapImage UriSource="{Binding Picture, Converter = ImageConverter}"/>
</Image.Source>
</Image>
Cependant j'ai deux erreurs :
"The TypeConverter for "IValueConverter" does not support converting from a string."
et "Cannot assign text value 'ImageConverter' into property 'converter' of type 'IValueConverter'".
Partager