/// <summary>
        /// Convert a <see cref="IItem"/> into an image representation.
        /// </summary>
        /// <param name="value"></param>
        /// <param name="targetType"></param>
        /// <param name="parameter"></param>
        /// <param name="culture"></param>
        /// <returns></returns>
        public object Convert(object value, Type targetType,
                              object parameter, CultureInfo culture)
        {
            var item = value as IItem;

            if (item == null)
            {
                return(Binding.DoNothing);
            }

            System.Windows.Media.ImageSource displayIcon = null;

            try
            {
                // a folder can be represented with a seperate icon for its expanded state
                if (item.ItemType == FSItemType.Folder)
                {
                    displayIcon = IconExtractor.GetFolderIcon(item.ItemPath,
                                                              item.IsExpanded).ToImageSource();
                }
                else
                {
                    displayIcon = IconExtractor.GetFileIcon(item.ItemPath).ToImageSource();
                }
            }
            catch
            {
            }

            return(displayIcon);
        }
Esempio n. 2
0
        /// <summary>
        /// Ask the shell to feed us the appropriate icon for the given file, but
        /// first try looking in our cache to see if we've already loaded it.
        /// </summary>
        private int ExtractIconIfNecessary(String path)
        {
            Icon   icon;
            Size   size = GetSmallIconSize();
            String ext  = Path.GetExtension(path);

            if (String.IsNullOrEmpty(ext))
            {
                ext = "folder";
            }
            if (this.imageList.Images[ext] != null)
            {
                return(this.imageList.Images.IndexOfKey(ext));
            }
            else
            {
                if (File.Exists(path))
                {
                    icon = IconExtractor.GetFileIcon(path, false, true);
                }
                else
                {
                    icon = IconExtractor.GetFolderIcon(path, false, true);
                }
                Image image = ImageKonverter.ImageResize(icon.ToBitmap(), size.Width, size.Height);
                this.imageList.Images.Add(ext, image); icon.Dispose(); image.Dispose();
                return(this.imageList.Images.Count - 1);
            }
        }
Esempio n. 3
0
 /// <summary>
 /// Assign a certain icon to this item.
 /// </summary>
 /// <param name="src"></param>
 public void SetDisplayIcon(ImageSource src = null)
 {
     if (src == null)
     {
         this.DisplayIcon = IconExtractor.GetFolderIcon(this.FullPath, true).ToImageSource();
     }
     else
     {
         this.DisplayIcon = src;
     }
 }
Esempio n. 4
0
        /// <summary>
        /// Ask the shell to feed us the appropriate icon for the given file, but
        /// first try looking in our cache to see if we've already loaded it.
        /// </summary>
        private int ExtractIconIfNecessary(String path)
        {
            Icon icon;
            Size size = GetSmallIconSize();

            if (File.Exists(path))
            {
                icon = IconExtractor.GetFileIcon(path, false, true);
            }
            else
            {
                icon = IconExtractor.GetFolderIcon(path, false, true);
            }
            Image image = ImageKonverter.ImageResize(icon.ToBitmap(), size.Width, size.Height);

            this.imageList.Images.Add(image); icon.Dispose(); image.Dispose();
            return(this.imageList.Images.Count - 1);
        }