我想制作一个显示文件系统的树视图。
public class FileSystem
{
public IList< Folder> folders;
public FileSystem()
{
foreach (DriveInfo di in DriveInfo.GetDrives())
{
Folder f = new Folder(di.Name);
f.fillSubFolders();
folders.Add(f);
}
}
}
public class FileItem
{
public string name;
public FileItem(string _name)
{
name = _name;
}
}
public class Folder
{
public string name;
public IList<Folder> subFolders;
public IList<FileItem> items;
public Folder(string _name)
{
name = _name;
subFolders = new List<Folder>();
items = new List<FileItem>();
}
public void fillSubFolders() {
foreach (string fl in Directory.GetFiles(name))
{
FileItem f = new FileItem(fl);
items.Add(f);
}
foreach (string dir in Directory.GetDirectories(name))
{
Folder f = new Folder(dir);
subFolders.Add(f);
f.fillSubFolders();
}
}
}
我应该在XAML代码中添加什么才能绑定数据?
<TreeView Height="311" HorizontalAlignment="Left" Name="treeView1" VerticalAlignment="Top" Width="199" ItemsSource="{Binding items}">
<TreeView.Resources>
<HierarchicalDataTemplate DataType="{Binding}">
</HierarchicalDataTemplate>
</TreeView.Resources>
</TreeView>