WPF simple file resource management

Source: Internet
Author: User

<Window X: class = "wpffolderexplorer. mainwindow "xmlns =" http://schemas.microsoft.com/winfx/2006/xaml/presentation "xmlns: x =" http://schemas.microsoft.com/winfx/2006/xaml "xmlns: My =" CLR-namespace: wpffolderexplorer "Title =" folder Explorer "Height =" 350 "width =" 525 "> <window. resources> <! -- Objectdataprovider: wraps and creates an object that can be used as the binding source. --> <Objectdataprovider X: Key = "rootfolderdataprovider"> <! -- Objectinstance: object instance --> <objectdataprovider. objectinstance> <! -- Fullpath: an attribute of the folder class --> <my: folder fullpath = "C: \ Program Files \"/> </objectdataprovider. objectinstance> </objectdataprovider> <! -- Hierarchicaldatatemplate: hierarchical data template --> 
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.IO;using System.Collections.ObjectModel;namespace WPFFolderExplorer{    public class Folder    {        private DirectoryInfo _folder;        private ObservableCollection<Folder> _subFolders;        private ObservableCollection<FileInfo> _files;        public Folder()        {            this.FullPath = @"c:\Program Files\";        }        public string Name        {            get            {                return this._folder.Name;            }        }        public string FullPath        {            get            {                return this._folder.FullName;            }            set            {                if (Directory.Exists(value))                {                    this._folder = new DirectoryInfo(value);                }                else                {                    throw new ArgumentException("must exist", "fullPath");                }            }        }        public ObservableCollection<FileInfo> Files        {            get            {                if (this._files == null)                {                    this._files = new ObservableCollection<FileInfo>();                    FileInfo[] fi = this._folder.GetFiles();                    for (int i = 0; i < fi.Length; i++)                    {                        this._files.Add(fi[i]);                    }                }                return this._files;            }        }        public ObservableCollection<Folder> SubFolders        {            get            {                if (this._subFolders == null)                {                    this._subFolders = new ObservableCollection<Folder>();                    DirectoryInfo[] di = this._folder.GetDirectories();                    for (int i = 0; i < di.Length; i++)                    {                        Folder newFolder = new Folder();                        newFolder.FullPath = di[i].FullName;                        this._subFolders.Add(newFolder);                    }                }                return this._subFolders;            }        }    }}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.