分组CollectionView的组可以水平呈现吗?

我正在按照这个答案实现一个ListBox,其ItemsPanel是一个WrapPanel,但有一个转折:我的ItemsSource是一个分组的CollectionView。将
GroupStyle
应用于我的ListBox后,该问题中显示的包装不起作用:组始终垂直显示。 窥探我的应用程序,原因如下: 如您所见,定义为ListBox的ItemsPanelTemplate的WrapPanel出现在每个GroupItem中的ItemsPresenter中;创建一个隐式的,垂直方向的StackPanel(粉红色框中的顶部项)来包含GroupItems本身。 有没有办法覆盖这种行为,所以GroupItems放在一个WrapPanel?我是否需要重新模板化整个ListBox? 更新:为了说明我对ListBox和CollectionView分组的实际操作,让我发布一个小XAML:
<Grid>
    <ListBox ItemsSource="{Binding}"                 
             ScrollViewer.VerticalScrollBarVisibility="Disabled"
             SelectionMode="Multiple"
             ItemContainerStyle="{StaticResource itemStyle}">
        <ListBox.GroupStyle>
            <GroupStyle>
                <GroupStyle.HeaderTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding Name}" FontWeight="Bold"/>
                    </DataTemplate>
                </GroupStyle.HeaderTemplate>
            </GroupStyle>
        </ListBox.GroupStyle>
        <ListBox.ItemTemplate>
            <DataTemplate DataType="{x:Type WpfApplication1:Item}">
                <StackPanel Orientation="Vertical">
                    <TextBlock Text="{Binding Name}" FontSize="10"/>
                    <TextBlock Text="{Binding Amount, StringFormat={}{0:C}}" FontSize="10"/>
                </StackPanel>
            </DataTemplate>
        </ListBox.ItemTemplate>
        <ListBox.ItemsPanel>
            <ItemsPanelTemplate>
                <WrapPanel Orientation="Vertical"/>
            </ItemsPanelTemplate>
        </ListBox.ItemsPanel>
    </ListBox>
</Grid>
GroupStyle
是它的核心:如果你删除它,GroupItems就不会被渲染,并且WrapPanel(你可以在上面的截图中看到出现在GroupItem下面)代替屏幕截图中的(StackPanel)98 。     
已邀请:
如果您在GroupStyle中定义了HeaderTemplate,则似乎只会出现此行为。 可以通过将GroupStyle.Panel属性设置为包含WrapPanel来更正它:
<ListBox.GroupStyle>
    <GroupStyle>
        <GroupStyle.HeaderTemplate>
            <DataTemplate>
                <TextBlock Text="{Binding Name}" FontWeight="Bold"/>
            </DataTemplate>
        </GroupStyle.HeaderTemplate>
        <GroupStyle.Panel>
            <ItemsPanelTemplate>
                <WrapPanel></WrapPanel>
            </ItemsPanelTemplate>
        </GroupStyle.Panel>
    </GroupStyle>
</ListBox.GroupStyle>
它看起来像这样:     
您应该能够从items控件(ListBox)替换组样式:
<ListBox.GroupStyle>
    <Style />
<ListBox.GroupStyle/>
或者,您还应该能够基于组项对象创建DataTemplate:
<DataTemplate DataType="{x:Type GroupItem}">
    <Panel />
</DataTemplate>
    

要回复问题请先登录注册