1

我有一个“TreeView which uses a customItemsPanel to show the first level of items in aStackPanel , but I need to show subitems in aStackPanel too. The problem is, the second level of items are shown in aWrapPanel , and asHierarchicalDataTemplate doesn't have anItemsPanel”属性我不知道该怎么做。这是我的 xaml:

<TreeView x:Name="treGlobalCards">
    <TreeView.ItemsPanel>
        <ItemsPanelTemplate>
            <StackPanel IsItemsHost="True" Orientation="{Binding Orientation,RelativeSource={x:Static RelativeSource.TemplatedParent}}"
                        MaxWidth="{Binding ActualWidth,RelativeSource={RelativeSource AncestorType={x:Type ScrollContentPresenter}}}"/>
        </ItemsPanelTemplate>
    </TreeView.ItemsPanel>
    <TreeView.ItemTemplate>
    <HierarchicalDataTemplate x:Key="CardTypeTemplate" ItemsSource="{Binding Cards}">
        <TextBlock Text="{Binding Path=CardType}"/>
    </HierarchicalDataTemplate>
    </TreeView.ItemTemplate>
</TreeView>
4

1 回答 1

0

创建一个使用 StackPanel 的新 DataTemplate,并将 HierachicalDataTemplate 的“ItemTemplate”设置为该新 DataTemplate。

IE


<DataTemplate x:Key="someTemp">
    <StackPanel />
</DataTemplate>

<HierarchicalDataTemplate x:Key="hierTemp" ItemSource="{Binding}" ItemTemplate="{StaticResource someTemp}" />

于 2010-04-08T13:34:34.743 回答