我有一个包含遵循此结构的对象的列表。这不是我正在使用的真正的课程,而是应该解释这个概念。WPF HierarchicalDataTemplate&ItemsControl
CLASSES
public class BaseType{}
public class TypeA : BaseType{}
public class TypeB: BaseType
{
public List<TypeA> TypeAList { get; private set; }
}
的ItemsControl的结合列表中是一个List<BaseType>
XAML现在
<ItemsControl>
<ItemsControl.Resources>
<HierarchicalDataTemplate DataType="{x:Type local:TypeB}" ItemsSource = "{Binding Path=TypeAList}">
<DataTemplate.Resources>
<Style TargetType="TextBlock">
<Setter Property="FontSize" Value="18"/>
<Setter Property="HorizontalAlignment" Value="Center"/>
</Style>
</DataTemplate.Resources>
<Grid>
<Ellipse Fill="Gold"/>
<StackPanel>
<TextBlock Margin="3,3,3,0"
Text="{Binding Path=Description}"/>
<TextBlock Margin="3,0,3,7"
Text="{Binding Path=Name}"/>
</StackPanel>
</Grid>
</HierarchicalDataTemplate>
<ItemsControl.Resources>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel></StackPanel>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
我期望看到的是所有类型A的对象在TypeB对象属性中找到要显示在Ite中msControl,而是我只看到TypeB对象,显示为为HierarchicalDataTemplate定义的样式。我在TreeView控件中使用了相同的数据模式,它显示的子项很好。
- 你不能在ItemsControl中使用HierarchicalDataTemplate吗?
- 你如何去在ItemsControl中显示父子关系?