0
我有一個包含遵循此結構的對象的列表。這不是我正在使用的真正的課程,而是應該解釋這個概念。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中顯示父子關係?