wpf treeview绑定 [英] wpf treeview binding

查看:154
本文介绍了wpf treeview绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我们应该在ItemsSource,DataType,ItemTemplate属性中写什么,如果有
一个项目列表?

  IList< string> items = new List< string>(); 
items.Add(item1);
items.Add(item2);
items.Add(item3);

XAML代码:

 < TreeView Name =treeView1> 
< TreeView.Resources>这是什么意思? - >
< HierarchicalDataTemplate DataType =??? ItemsSource ={Binding ???}>< / HierarchicalDataTemplate>
< /TreeView.Resources>
< / TreeView>


解决方案

要充分了解如何使用wpf treeview与数据绑定,我按顺序浏览了以下教程 -



1)使用递归的一个非常简单的树视图绑定示例



http://testdrivendevelopment.wordpress.com/2008/07/15 / databinding-wpf-treeview-using-recursion /



2)Claus Konrads使用树视图进行数据绑定的简单示例。这是我遇到的最直截了当的例子,应该能够让任何新手加入wpf。



http://blog.clauskonrad.net/2011/04/how-to-make-hierarchical-treeview.html



3)Mike Hillbergs教程详细介绍了treeview的内容,它与其他wpf控件的对比以及如何绑定数据。



http://blogs.msdn.com/b/mikehillberg/archive/2009/10/30/treeview-and-hierarchicaldatatemplate-step-by-step.aspx


Is there any simple tutorial for beginners about treeview binding in WPF?

What should we write in ItemsSource, DataType, ItemTemplate attributes if there's one List of items?

IList<string> items = new List<string>();
items.Add("item1");
items.Add("item2");
items.Add("item3");

XAML code:

<TreeView Name="treeView1">  
    <TreeView.Resources> <!-- what does it mean? -->
        <HierarchicalDataTemplate DataType="???" ItemsSource="{Binding ???}"></HierarchicalDataTemplate>  
    </TreeView.Resources>  
</TreeView>

解决方案

To Fully understand how to use the wpf treeview with data binding, I went through the following tutorials in order -

1) A very simple example of treeview binding using recursion

http://testdrivendevelopment.wordpress.com/2008/07/15/databinding-wpf-treeview-using-recursion/

2) Claus Konrads simple example of data binding with the treeview. It's the most straightforward example I have come across and should get any newcomers to wpf up to speed.

http://blog.clauskonrad.net/2011/04/how-to-make-hierarchical-treeview.html

3) Mike Hillbergs tutorial shows, in detail, the ins and outs of the treeview, how it compares to other wpf controls, and how to bind data.

http://blogs.msdn.com/b/mikehillberg/archive/2009/10/30/treeview-and-hierarchicaldatatemplate-step-by-step.aspx

这篇关于wpf treeview绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆