我有一个带有两个相似子树的分层数据结构:
Iteration:
string Name
string Image
ObservableCollection<Iteration> SubIterations
ObservableCollection<Iteration> BacklogIterations
我想使用两个树视图来呈现树的两个稍微不同的视图。
- Tree1:显示子迭代
- Tree2:显示 BacklogIterations
元素应该显示相同,但需要使用不同的属性来拾取子项。
即我想参数化 HierarchicalDataTemplate 中的 ItemsSource:
<HierarchicalDataTemplate x:Key="IterationItem"
ItemsSource="{Binding SubIterations}"
>
<StackPanel Orientation="Horizontal">
<Image Width="32" Height="32"
Margin="3,0" Source="{Binding Picture}" />
<TextBlock Text="{Binding Name}" />
</StackPanel>
</HierarchicalDataTemplate>
<TreeView ItemsSource="{Binding RootSprintIteration}">
</TreeView>
<TreeView ItemsSource="{Binding RootBacklogIteration}">
</TreeView>
如何让第二棵树中的 HierarchicalDataTemplate 使用不同的 ItemsSource?我不想复制整个 HierarchicalDataTemplate 定义只是为了更改 ItemsSource。