让 ItemsSource 将集合视为单个项目,而不是对其进行迭代?
我有一个显示对象属性的TreeView
。属性之一是大字节数组。
TreeView 的 ItemsSource
显然将其视为子节点的集合,但我真正想要的是一个子节点,显示仍然可以展开/折叠的整个数组。
例如,目前
- MyObject
Prop1
Prop2
- PropWithBytes
1
2
3
etc
我想要的:
- MyObject
Prop1
Prop2
- PropWithBytes
1, 2, 3 etc
有什么方法可以告诉树将集合视为单个节点吗?
如果我不希望实际数据仍然是一个单独的节点,我可以轻松编写一个 DataTemplate(而不是 HierarchicalDataTemplate)来就地显示它。我还可以使用使用 Expander
的 DataTemplate 来隐藏数据,该数据工作正常,但看起来很难看。
I have a TreeView
showing an object's properties. One of the properties is a large byte array.
TreeView's ItemsSource
obviously treats this as a collection of child nodes, but what I actually want is ONE child node showing the entire array that can still be expanded/collapsed.
eg currently
- MyObject
Prop1
Prop2
- PropWithBytes
1
2
3
etc
What I want:
- MyObject
Prop1
Prop2
- PropWithBytes
1, 2, 3 etc
Is there any way to tell the Tree to treat the collection as a single node?
If I didn't want the actual data to still be a separate node I could easily write a DataTemplate
(as opposed HierarchicalDataTemplate
) to to display it in place. I can also use a DataTemplate
that uses an Expander
instead to hide the data which works fine, but looks ugly.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我正确理解你的问题 - 尝试使用 ValueConverter 它将检查传递的值是否为字节数组(如果是字节数组 - 返回它的字符串表示形式)。
If I understand your question correctly - try to use ValueConverter which will check if passed value is byte array or not (in case of byte array - returns it's string representation).