0
我想使樹視圖顯示文件系統。Treeview綁定wpf
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>
此鏈接不再有效 – 2012-04-20 09:52:24