我有如下勢必圖像:在image.source不圖使用轉換器
<Image x:Name="ImgFoto" Source="{Binding Path=Foto,
Converter={StaticResource imageConverter}, Mode=TwoWay,
UpdateSourceTrigger=PropertyChanged}" Stretch="Fill"
HorizontalAlignment="Left"
Height="148" Margin="25,23,0,0" VerticalAlignment="Top"
Width="193"/>"
「圖片」是Image類型的SQL領域
我的轉換器類:
public sealed class ImageConverter : IValueConverter
{
public object Convert(object value, Type targetType,
object parameter, CultureInfo culture)
{
try
{
return new BitmapImage(new Uri((string)value));
}
catch
{
return new BitmapImage();
}
}
public object ConvertBack(object value, Type targetType,
object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
我的問題是,當你運行該應用程序的圖像顯示爲空白。
我編輯了你的標題。請參閱:「[應該在其標題中包含」標籤「](http://meta.stackexchange.com/questions/19190/)」,其中的共識是「不,他們不應該」。 – 2014-11-03 01:30:48
這裏很難說出什麼問題。嘗試查看*** Output ***窗口,看看是否有任何錯誤通知。順便說一句,我認爲你不需要任何自定義轉換器在這裏。默認的Converter可以將URI字符串轉換爲一些ImageSource。 – 2014-11-03 01:52:06