WPF 树视图的不同级别的样式不同?
我有一个非常扁平结构的树视图,只有两层项目 - 主项目和一层子项目。 我正在使用 WPF MVVM,并且想要一种以不同方式设置两个级别的样式的方法,但不知道如何实现。
我将树视图绑定到 ViewModel 中的 ObservableCollection,每个元素都有一个用于下一级别的 ObservableCollection。
有什么帮助吗?
I have a very flat-structured treeview with only two levels of items - the main ones, and one level of subitems. I am using WPF MVVM and would like a way to style the two levels differently, but have no idea how.
I bind the treeview to an ObservableCollection in my ViewModel, and each element has one more ObservableCollection for the next level.
Any help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这可以通过 DATABINDING 和使用 DATATEMPLATES 来完成。
您将设计两个数据模板。 1 个作为 Hierarchical DataTemplate,另一个作为较低级别的标准版本(这是因为您只使用 2 个级别)
然后将 HierarchicalDataTemplate 的 ItemTemplate 设置为常规 DataTemplate
详细信息可以在此处找到: http://msdn.microsoft.com/en-us/magazine/cc700358.aspx
代码片段上述网站:
This can be accomplished via DATABINDING and using DATATEMPLATES.
You would design two DataTemplates. 1 as a Hierarchical DataTemplate and the other as a standard version for your lower level (this is since you only utilize 2 levels)
Then set the ItemTemplate of your HierarchicalDataTemplate to the regular DataTemplate
Details can be found here: http://msdn.microsoft.com/en-us/magazine/cc700358.aspx
Code snippet from the above site: