Source="{Binding Path=FilenameUri,
Converter={StaticResource LocalUriToImageConverter}}">
1: public class UriToImageConverter : IValueConverter
2: {
3:
4: public object Convert(object value, Type targetType, object parameter,
System.Globalization.CultureInfo culture)
5: {
6: if (value == null)
7: {
8: return null;
9: }
10:
11: if (value is string)
12: {
13: value = new Uri((string)value);
14: }
15:
16: if (value is Uri)
17: {
18: BitmapImage bi = new BitmapImage();
19: bi.BeginInit();
20: bi.DecodePixelWidth = 80;
21: //bi.DecodePixelHeight = 60;
22: bi.UriSource = (Uri)value;
23: bi.EndInit();
24: return bi;
25: }
26:
27: return null;
28: }
29:
30: public object ConvertBack(object value, Type targetType, object parameter,
System.Globalization.CultureInfo culture)
31: {
32: throw new Exception("The method or operation is not implemented.");
33: }
34:
35: }
下一篇:我的友情链接
-
WPF依赖属性、附加属性、属性继承、类型转换详解
WPF依赖属性、附加属性、属性继承、类型转换详解
wpf 微软 C# Parse 属性值 -
向上类型转换VS向下类型转换
子类转换成父类时的规则:将一个父类的引用指向一个子类的对象,称为向上转型(upcasting)
多态 java 类 父类 子类