创建 WPF 混合控件(TreeView + DataGrid = DataTreeGrid)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5502513/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 22:43:51  来源:igfitidea点击:

Creating a WPF Hybrid Control (TreeView + DataGrid = DataTreeGrid)

wpfdatagridtreeviewcustom-controls

提问by NemoStein

I need to create a TreeView that hold synchronized data, like a DataGrid.

我需要创建一个保存同步数据的 TreeView,如 DataGrid。

To clarify, take a look at this image:
DataTreeGrid Custom Control

为了澄清,请看一下这张图片:
DataTreeGrid 自定义控件

So, I have a TreeView at left side with columns at right side.
The data will come from objects like this:

所以,我在左侧有一个 TreeView,右侧有一个列。
数据将来自这样的对象:

public NodeData Parent;
public List<NodeData> Children;

public String Label;

public Boolean DataA;
public Boolean DataB;
public Boolean DataC;
public Boolean DataX;
public Boolean DataY;
public Boolean DataZ;

How can I create this?

我怎样才能创建这个?

回答by Johan Larsson

Thisis the best control I have found for presenting data like this. It does not require an interface/basclass on the viemodels and uses HierarchicalDataTemplate

是我发现的用于呈现此类数据的最佳控件。它不需要 viemodels 上的接口/基类并使用HierarchicalDataTemplate

回答by Rachel

To me this looks like a regular DataGrid with a few Groupings set on it

对我来说,这看起来像一个普通的 DataGrid,上面设置了一些分组

So in your case you would create a DataGrid that groups on Root, Node #, Node 2nd Number, and Node 3rd Number.

因此,在您的情况下,您将创建一个 DataGrid,它在 Root、Node #、Node 2nd Number 和 Node 3rd Number 上分组。

Also flatten your list of NodeData so it is a single list with each item containing properties for Root, NodeLevel1, NodeLevel2, and NodeLevel3

还将您的 NodeData 列表展平,使其成为单个列表,其中每个项目都包含 Root、NodeLevel1、NodeLevel2 和 NodeLevel3 的属性