我正在實現一個ListBox,其ItemsPanel是一個WrapPanel as per this answer,但有一個轉折:我的ItemsSource是分組 CollectionView。將GroupStyle
應用於我的ListBox,該問題中顯示的包裝不起作用:組始終垂直顯示。分組的CollectionView可以水平顯示嗎?
Snoop荷蘭國際集團在我的應用程序,這裏的原因:
正如你所看到的,WrapPanel,定義爲我的列表框的ItemsPanelTemplate,出現在ItemsPresenter 內每個GroupItem;一個隱含的,垂直定向的StackPanel(粉紅色框中的頂部項目)被創建來包含GroupItems本身。
有沒有辦法來覆蓋這種行爲,所以GroupItems被放置在一個WrapPanel?我需要重新模板整個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的位置。
爲什麼你的WrapPanel的'Orientation'設置爲'垂直'如果你想要一個水平列表?我無法形象地看到你的目標是什麼。 – 2011-04-02 03:04:43
@ H.B。如果將它設置爲「垂直」,但禁用「垂直」滾動條,則WrapPanel將在增加高度時抓取多餘的行,但只會將*項橫向移出屏幕。查看「多列列表框」的答案,我上面鏈接了一個很好的可視化我的意思。 – 2011-04-02 05:09:37