带有由不同列表绑定的复选框的树视图
我有一个这样的类:
public class Project
{
List<Object> list1;
List<Object> list2;
}
我想在树视图控件中显示它,如下所示:
Checkbox + "Listing1"
--> Checkbox + Object 1 of list1
--> Checkbox + Object 2 of list1
Checkbox + "Listing2"
--> Checkbox + Object 1 of list2
-->Checkbox + Object 2 of list2
我最大的问题是区分两个列表+一些额外的内容:如果list2不包含任何对象,则“Listing2”标题可能不包含被显示。
有人知道我该怎么做吗?
I have a class like this :
public class Project
{
List<Object> list1;
List<Object> list2;
}
I want to show this in a treeview control like as follows :
Checkbox + "Listing1"
--> Checkbox + Object 1 of list1
--> Checkbox + Object 2 of list1
Checkbox + "Listing2"
--> Checkbox + Object 1 of list2
-->Checkbox + Object 2 of list2
My biggest problem is making the difference between the 2 lists + some extra : if list2 does not contain any objects, the "Listing2" header may not be shown.
Does anybody have any good idea how I can do this ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以通过扩展 TreeViewItem 类来创建一个类 TreeViewItemWithCheckbox ,如下所示:
然后您需要从 2 个列表中添加树视图节点,如下所示:
You can create one class TreeViewItemWithCheckbox by extending TreeViewItem class like below :
Then you need to add treeview nodes from 2 list like below :
这可以在没有 TreeView 的情况下解决 - 只需 2 个复选框和 2 个具有特定 ItemTemplate 的 ItemsControl。
我更喜欢用这种方式解决这个问题:
至于你的额外:,你可以将 Visibility 绑定到
Project
类中的属性,它看起来像:代码:
...如果我理解正确的话...
This can be solved without TreeView - Just 2 CheckBoxes and 2 ItemsControl with specific ItemTemplate.
I prefer this way of solving this problem:
As for your extra: you can bind Visibility to the property in your
Project
class, which will be looks like:and than in the code:
...if I understand you right...
如果您的第一个“列表”项目是静态的,您可以执行类似的操作
要隐藏没有子元素的元素,您需要一些代码。
当然对于这两个列表。
If your first "Listing" items are static, you can do something like this
To hide elements without children you need a bit of code.
For both lists of course.