Wpf 带wrappanel的Treeview-灵活分组

Wpf 带wrappanel的Treeview-灵活分组,wpf,treeview,datatemplate,grouping,wrappanel,Wpf,Treeview,Datatemplate,Grouping,Wrappanel,我正试图解决treeview的问题。 我想在树状视图节点中的wrappanel中获得订购的项目(UserControls) -Group |---------------------------------------------| |Item Item Item Item Item Item Item Item Item | |---------------------------------------------| +Group +Group 如果窗口宽度(和沿树视图宽度)被抑制,

我正试图解决treeview的问题。 我想在树状视图节点中的wrappanel中获得订购的项目(UserControls)

-Group
 |---------------------------------------------|
 |Item Item Item Item Item Item Item Item Item |
 |---------------------------------------------|
+Group
+Group
如果窗口宽度(和沿树视图宽度)被抑制,并且项目不适合一行,则应将这些项目订购到下一行

-Group
 |-------------------------|
 |Item Item Item Item Item |
 |Item Item Item Item      |
 |-------------------------|
+Group
+Group
我已经完成了上面的示例,它不会将项目放在下一行。这在没有Treeview的情况下可以正常工作,但在Treeview节点中缺少了一些内容

    <DataTemplate x:Key="GroupTemplateFrontPage">
        <Border BorderBrush="AliceBlue" BorderThickness="1" CornerRadius="10"
                Background="{StaticResource TreeViewItemBackground}" >
            <Expander HeaderTemplate="{DynamicResource HeaderTemplate}" 
                      Header="{Binding}" IsTabStop="False" HorizontalAlignment="Left" 
                      IsEnabled="True" ExpandDirection="Down" IsExpanded="True">
                <Grid Margin="5,5,5,5">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition />
                    </Grid.ColumnDefinitions>
                    <ListBox Margin="10,39,0,0" VerticalAlignment="Top" ScrollViewer.VerticalScrollBarVisibility="Disabled" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ItemsSource="{Binding Modems}">
                    <ListBox.ItemsPanel>
                        <ItemsPanelTemplate>
                            <WrapPanel                                    
                                HorizontalAlignment="Stretch"
                                ScrollViewer.HorizontalScrollBarVisibility="Disabled" 
                                ScrollViewer.VerticalScrollBarVisibility="Disabled"/>
                        </ItemsPanelTemplate>
                    </ListBox.ItemsPanel>
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <Grid>
                                <Controls:UserControlItem Margin="4" />
                            </Grid>
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                    </ListBox>
                </Grid>
            </Expander>
        </Border>
    </DataTemplate>





        <StackPanel Orientation="Vertical">
            <TextBlock Text="Treeview" />
            <TreeView Name="_treeView" ScrollViewer.HorizontalScrollBarVisibility="Disabled"
              Margin="0,0,0,0" 
              ItemsSource="{Binding}" 
              ItemTemplate="{StaticResource GroupTemplateFrontPage}"  />
        </StackPanel>

树视图项设置
项span
应执行以下操作:

<TreeView.ItemContainerStyle>
    <Style TargetType="TreeViewItem">
        <Setter Property="ItemsPanel">
            <Setter.Value>
                <ItemsPanelTemplate>
                    <WrapPanel />
                </ItemsPanelTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</TreeView.ItemContainerStyle>

同时关闭水平滚动以允许换行:

<TreeView ScrollViewer.HorizontalScrollBarVisibility="Disabled" ...>

是的,对我来说是同一个问题,这样做有效()