【问题标题】:Treeview binding wpf树视图绑定 wpf
【发布时间】:2011-03-15 10:55:49
【问题描述】:

我想制作一个显示文件系统的树形视图。

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>

【问题讨论】:

    标签: wpf binding treeview


    【解决方案1】:

    您可能想查看this article(尤其是“查看实现”部分)。

    【讨论】:

      【解决方案2】:

      以下链接可能会有所帮助

      http://www.mattlong.com.au/?p=37

      【讨论】:

        猜你喜欢
        • 2012-02-20
        • 1970-01-01
        • 2015-07-10
        • 2011-07-14
        • 2011-05-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多