我的课程结构如下:
public class WTRun : INotifyPropertyChanged
{
public WTRun()
{
}
# Local variable definitions removed
# Property gets & sets removed
# NotifyPropertyChanged code removed
public Guid RunId
public int RunNumber
public DateTime? RunStartTime
public DateTime? RunEndTime
public string RunComment
public int MapId
public RunConfiguration Configuration
public ObservableCollection<StepMetric> StepMetrics
public ObservableCollection<BlockMetric> BlockMetrics
public ObservableCollection<Medusa> Medusas
public ObservableCollection<PIV> PIVs
public ObservableCollection<CMotion> CMotions
}
该类包装在ObservableCollection中,然后绑定到TreeView。 我对如何设置TreeView以使其正确显示项目感到困惑。
我希望TreeView看起来像这样:
Root
+--(RunNumber)
| +--"StepMetrics"
| | +--(StepMetric IDs)
| +--"BlockMetrics"
| | +--(BlockMetric IDs)
| +--"Medusas"
| | +--(Medusa IDs)
| +--"PIVs"
| | +--(PIV IDs)
| +--"CMotions"
| +--(CMotion IDs)
|--(RunNumber)
...etc
我一直在努力尝试使用模板,但是到目前为止只能显示RunNumbers:
<TreeView.Resources>
<HierarchicalDataTemplate DataType="{x:Type VMEntities:WTRun}" >
<TextBlock Text="{Binding RunNumber }" Margin="1" />
</HierarchicalDataTemplate>
<HierarchicalDataTemplate DataType="{x:Type VMEntities:BlockMetric}">
<TextBlock Text="{Binding BlockIndex}"/>
</HierarchicalDataTemplate>
</TreeView.Resources>
这显然不是一次彻底的尝试......
这是正确的方法吗?