不工作我在窗口數據綁定圖像UriSource
<Image Source="{Binding Path=MYImage, Converter={StaticResource ResourceKey=imageConverter}}" />
一個像我一直在使用一個值轉換器也試過:
public 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();
}
}
,創造一個依賴屬性吧。
public string MYImage
{
get { return (string)GetValue(MYImageProperty); }
set { SetValue(MYImageProperty, value); }
}
public static readonly DependencyProperty MYImageProperty=DependencyProperty.Register("PickerImage",typeof(string),typeof(MYClass),new PropertyMetadata("/MYProject;component/pic.png"));
但是當我使用它,不顯示圖像!
你有沒有在MyImage中嘗試過相對路徑。 –