Пример #1
0
        private void Populate(string header, string tag, TreeView _root, TreeViewItem _child, bool isfile)       //create the tree view
        {
            try
            {
                Icon         ic       = SysIcon.OfPath(tag);
                TreeViewItem _driitem = new TreeViewItem();
                _driitem.Tag    = tag;
                _driitem.Header = header;

                _driitem.Expanded += new RoutedEventHandler(_driitem_Expanded);
                if (!isfile)
                {
                    _driitem.Items.Add(new TreeViewItem());
                }

                if (_root != null)
                {
                    _root.Items.Add(_driitem);
                }
                else
                {
                    _child.Items.Add(_driitem);
                }
            }
            catch (System.NullReferenceException ex)
            { Console.WriteLine(ex.InnerException); }
            catch (System.UnauthorizedAccessException unauth)
            { Console.WriteLine(unauth.InnerException); }
        }
Пример #2
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            try {
                string tag = value.ToString();


                Icon ic = SysIcon.OfPath(tag);

                ImageSource imageSource = Imaging.CreateBitmapSourceFromHIcon(
                    ic.Handle,
                    Int32Rect.Empty,
                    BitmapSizeOptions.FromEmptyOptions());
                //var bitmap = ic.ToBitmap();
                //BitmapImage source = bitmap;
                return(imageSource);
            }
            catch (NullReferenceException e1)
            {
                Console.WriteLine(e1.InnerException);
                return(new object());
            }
        }