Example #1
0
        private List <IconTreeViewItem> GetAllAppsFoldersAsTree(String Path)
        {
            List <IconTreeViewItem> AllAppsItems = new List <IconTreeViewItem>();

            foreach (var s in Directory.EnumerateFiles(Path))
            {
                IconTreeViewItem t = AllAppsListGetItem(s);
                /*((string)(((t.Header as DockPanel).Children[1] as System.Windows.Controls.Label).Content as string)*/
                /*(string)(((t.Header as DockPanel).Children[1] as System.Windows.Controls.Label).Content as string)*/
                if (!(t.Header.ToString().ToLower().Contains("desktop")))
                {
                    /*if (System.IO.Path.GetExtension(t.Tag.ToString()).Contains("lnk"))
                     * {
                     *  t.Tag = GetTargetPath(t.Tag.ToString());
                     * }*/
                    AllAppsItems.Add(t);
                }
            }

            foreach (var s in Directory.EnumerateDirectories(Path))
            {
                IconTreeViewItem t = AllAppsListGetItem(s);
                /*if (((string)(((t.Header as DockPanel).Children[1] as System.Windows.Controls.Label).Content as string) != "desktop") & ((string)(((t.Header as DockPanel).Children[1] as System.Windows.Controls.Label).Content as string) != "desktop.ini"))*/
                /*if ((t.Header.ToString() != "desktop") & (t.Header.ToString() != "desktop.ini"))*/
                if (!(t.Header.ToString().ToLower().Contains("desktop")))
                {
                    if (t.Items.Count != 0)
                    {
                        AllAppsItems.Add(t);
                    }
                }
            }
            return(AllAppsItems);
        }
Example #2
0
        public IconTreeViewItem AllAppsListGetItem(String path)
        {
            var target = path;

            if (System.IO.Path.GetExtension(path).Contains("lnk"))
            {
                target = GetTargetPath(path);
            }

            IconTreeViewItem item = new IconTreeViewItem()
            {
                Tag = target
            };

            if (Directory.Exists(target))
            {
                foreach (var s in Directory.EnumerateFiles(target))
                {
                    var subItem = AllAppsListGetItem(s);
                    subItem.MinWidth = item.MinWidth + 16;
                    item.Items.Add(subItem);
                }
            }

            item.Header = System.IO.Path.GetFileNameWithoutExtension(path);

            if (Directory.Exists(item.Tag.ToString()))
            {
                item.MouseDoubleClick += Item_Opened;
            }
            else if (File.Exists(item.Tag.ToString()))
            {
                item.Expanded += Item_Opened;
            }

            if ((File.Exists(item.Tag.ToString())) | (Directory.Exists(item.Tag.ToString())))
            {
                //var fi = new SHFILEINFO();

                //var img = Win32.SHGetFileInfo(item.Tag.ToString(),
                //    0,
                //    ref fi,
                //    (uint)Marshal.SizeOf(fi),
                //    Win32.SHGFI_ICON | Win32.SHGFI_LARGEICON);

                //ImageSource entryIconImageSource = Imaging.CreateBitmapSourceFromHIcon(
                //    SystemIcons.Shield.Handle,
                //    Int32Rect.Empty,
                //    BitmapSizeOptions.FromWidthAndHeight(SystemScaling.RealPixelsToWpfUnits(16), SystemScaling.RealPixelsToWpfUnits(16)));

                item.Icon = new Canvas()
                {
                    Width      = 16,
                    Height     = 16,
                    Background = (ImageBrush) new DiskItemToIconImageBrushConverter().Convert(new DiskItem(item.Tag.ToString()), null, 64, null)
                };
            }

            return(item);
        }