Converter
public class ImgPathConvert : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (value == null) return null; string CommadnFolderPath = System.Environment.CurrentDirectory; string FilePath = System.IO.Path.Combine(CommadnFolderPath, @"Picture\Server\GroupPage\"); string ImagePath; switch((SyncModel.PlatformType)value) { case SyncModel.PlatformType.DoNetClient : ImagePath = FilePath + "server_pc.png"; break; case SyncModel.PlatformType.DoNetClientAIO: ImagePath = FilePath + "server_aio.png"; break; case SyncModel.PlatformType.DoNetClientNB: ImagePath = FilePath + "server_nb.png"; break; case SyncModel.PlatformType.DoNetClientTable: ImagePath = FilePath + "server_tablet.png"; break; case SyncModel.PlatformType.DoNetClientMSIAIO: ImagePath = FilePath + "server_aio_msi.png"; break; case SyncModel.PlatformType.DoNetClientMSINB: ImagePath = FilePath + "server_nb_msi.png"; break; case SyncModel.PlatformType.DoNetClientMSITable: ImagePath = FilePath + "server_tablet_msi.png"; break; default : ImagePath = FilePath + "server_pc.png"; break; } Uri uri = new Uri(ImagePath, UriKind.Absolute); //Uri uri = new Uri((value as string),UriKind.Relative); ImageBrush imgBru = new ImageBrush(); BitmapImage bImg = new BitmapImage(); bImg.BeginInit(); bImg.CacheOption = BitmapCacheOption.OnLoad; bImg.UriSource = uri; bImg.EndInit(); imgBru.ImageSource = bImg; imgBru.Stretch = Stretch.Fill; bImg.Freeze(); return imgBru; // return (isVisible ? Visibility.Visible : Visibility.Hidden); } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { return value; // throw new InvalidOperationException("Not yet support this function!"); } }
public class BoolVisibleConvert : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { bool isVisible; if (value == null || !(value is bool)) { isVisible = false; } else { isVisible = (bool)value; } return (isVisible ? Visibility.Visible : Visibility.Hidden); } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new InvalidOperationException("Not yet support this function!"); } }
public class DateTimeToStringConvert : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { DateTime d = (DateTime)value; if (DateTime.Equals(d, DateTime.MinValue)) return string.Empty; else return d; } public object ConvertBack(object value, Type targetType, object parameter,CultureInfo culture) { throw new InvalidOperationException("Not yet support this function!"); } }
posted on 2014-05-27 23:51 JackSlaterYu 阅读(301) 评论(0) 编辑 收藏 举报