none
这种样式用TreeView还是嵌套Listbox? RRS feed

全部回复

  • 你好,

    可以在Treeview中嵌套ListBox实现TreeViewItems的横向排列。以下是我实现横向排列的代码:

     <TreeView x:Name="tvList" Grid.Column="0" ItemsSource="{Binding Processes}"  Grid.Row="2"  Margin="0"   BorderBrush="#FFF1F1F1" >
                <TreeView.ItemTemplate >
                    <HierarchicalDataTemplate ItemsSource="{Binding Processes}"   >
                        <StackPanel Orientation="Horizontal">
                            <ListBox ItemsSource="{Binding Processes}"  BorderThickness="0">
                                <ListBox.ItemTemplate>
                                    <HierarchicalDataTemplate>
                                        <WrapPanel>
                                            <TextBlock Text="{Binding Path=Name}"  Margin="10,0,0,0" HorizontalAlignment="Center"/>
                                        </WrapPanel>
                                    </HierarchicalDataTemplate>
                                </ListBox.ItemTemplate>
                                <ListBox.Template>
                                    <ControlTemplate TargetType="{x:Type ListBox}">
                                        <WrapPanel Orientation="Horizontal" IsItemsHost="True"/>
                                    </ControlTemplate>
                                </ListBox.Template>
                            </ListBox>
                        </StackPanel>
                    </HierarchicalDataTemplate>
                </TreeView.ItemTemplate>
         </TreeView>

    谢谢

    Daisy  Tian


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    2020年9月11日 7:13