码迷,mamicode.com
首页 > 其他好文 > 详细

Converter

时间:2014-06-07 02:49:49      阅读:186      评论:0      收藏:0      [点我收藏+]

标签:c   style   class   blog   code   java   

bubuko.com,布布扣
    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!");
        }
    }
bubuko.com,布布扣
bubuko.com,布布扣
    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!");
        }
    }
bubuko.com,布布扣
bubuko.com,布布扣
    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!");
        }
    }
bubuko.com,布布扣

 

Converter,布布扣,bubuko.com

Converter

标签:c   style   class   blog   code   java   

原文地址:http://www.cnblogs.com/jackslateryu/p/3756218.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!