FileToVisualConverter

    public class StringToVisualConverter : IValueConverter
    {
        #region IValueConverter 成員

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (null != value)
            {
                string str_ExePath = value.ToString();
                if (!System.IO.File.Exists(str_ExePath)) return null;

                System.Drawing.Icon icon = System.Drawing.Icon.ExtractAssociatedIcon(str_ExePath);
                return System.Windows.Interop.Imaging.CreateBitmapSourceFromHIcon(
                            icon.Handle,
                            new Int32Rect(0, 0, icon.Width, icon.Height),
                            System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions());
            }
            return null;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        #endregion
    }

 

posted @ 2018-12-21 17:14  HotSky  阅读(117)  评论(0编辑  收藏  举报