首页 > 代码库 > Converter
Converter
public class ImgPathConvert : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (value =http://www.mamicode.com/= 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 =http://www.mamicode.com/= 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!"); } }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。