绑定到Treeview WPF [英] binding to a treeview WPF
本文介绍了绑定到Treeview WPF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将列表绑定到树视图,但是目前我只能让列表中的第一项显示在树视图中
我有一个Person类,其中有4个字符串项.
我绑定到具有List< person>
的属性
我的xaml是
I am trying to bind a list to a treeview, but currently i can only get the First item in the list to show in my treeview
I have a Person class with 4 string items in it.
I''m binding to a property with a List<person>
My xaml is
<TreeView>
<TreeViewItem Header="People">
<TextBlock>
<TextBlock Text={Binding GetPersons/FirstName}/>
<TextBlock Text={Binding GetPersons/LastName}/>
</TextBlock>
</TreeViewItem>
<TreeView>
我尝试在Treeview级别添加itemsSource,但是我认为我的语法不正确.
结果我正在寻找的是在根目录下展开的项目,我有4个条目.
I''ve tried adding the itemsSource at the Treeview level, but i don''t think my syntax is correct.
Result i''m looking for is that on root expand i have 4 entries.
推荐答案
您应该看一下此页面的底部:
http://msdn.microsoft.com/en-us/library/system. windows.controls.treeview.aspx [ ^ ]
You should take a look at the bottom of this page:
http://msdn.microsoft.com/en-us/library/system.windows.controls.treeview.aspx[^]
<treeview>
<treeviewitem header="Employee1">
<treeviewitem header="Jesper" />
<treeviewitem header="Aaberg" />
<treeviewitem header="12345" />
</treeviewitem>
<treeviewitem header="Employee2">
<treeviewitem header="Dominik" />
<treeviewitem header="Paiha" />
<treeviewitem header="98765" />
</treeviewitem>
</treeview>
要使用文本框,我需要执行以下操作:
To use a text box I do something like:
<treeviewitem>
<treeviewitem.header>
<TextBlock Text={Binding GetPersons/FirstName}/>
</treeviewitem.header>
</treeviewitem>
这篇关于绑定到Treeview WPF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文