列表框分组和ItemsPanel [英] ListBox Grouping and ItemsPanel
问题描述
我想在分组的listBox中水平显示项目
i want to display the items horizontally in a grouped listBox
<ListBox
ItemsSource="{Binding Source={StaticResource cvs}}"
HorizontalContentAlignment="Stretch"
ItemsPanel="{StaticResource HorizontalItemsPanel}"
Grid.Row="2"
VirtualizingPanel.IsVirtualizingWhenGrouping="True"
VirtualizingPanel.IsVirtualizing="True"
VirtualizingPanel.VirtualizationMode="Recycling"
VerticalContentAlignment="Stretch"
ItemTemplate="{DynamicResource LBDataTemplate}"
Grid.RowSpan="2">
<ListBox.GroupStyle>
<GroupStyle>
<GroupStyle.ContainerStyle>
<Style TargetType="{x:Type GroupItem}">
<Setter Property="Margin"
Value="0,0,0,5" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type GroupItem}">
<Expander IsExpanded="False"
BorderThickness="0">
<Expander.Header>
<DockPanel Height="30"
Background="AliceBlue">
<TextBlock FontWeight="Bold"
Text="{Binding Path=Name}"
Margin="5,0,0,0"
Width="100" />
<TextBlock FontWeight="Bold"
Foreground="Red"
Text="{Binding Path=ItemCount}" />
</DockPanel>
</Expander.Header>
<Expander.Content>
<ItemsPresenter />
</Expander.Content>
</Expander>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</GroupStyle.ContainerStyle>
</GroupStyle>
</ListBox.GroupStyle>
</ListBox>
LBDataTemplate 包含带有照片和一些文本的定制控件
the LBDataTemplate contain a cutom control with a photo and some texts
ItemsPanel 只是具有固定宽度的包装板
the ItemsPanel is just a wrap panelwith a fixed width
<ItemsPanelTemplate x:Key="HorizontalItemsPanel">
<WrapPanel IsItemsHost="True" Width="1000"
Orientation="Horizontal" />
</ItemsPanelTemplate>
列表框本身绑定到具有在后面的代码中定义的GroupDescription的collectionViewSource
the listbox itself is bound to a collectionViewSource with a GroupDescription defined in the code behind
var cvs = FindResource("cvs") as CollectionViewSource;
cvs.GroupDescriptions.Clear();
cvs.GroupDescriptions.Add(new PropertyGroupDescription("SEA_DEBUT", new JourConverter()));
cvs.Source = folks;
问题在于,使用这种布局,甚至使用简单的文本块作为itemTemplate,我的表现都非常差.
the problem is that i have a very very poor performance with this layout , and even with a simple textblock as an itemTemplate .
同一模板对于标准的垂直面板容器也可以正常工作,
the same template work fine with standard vertical panel container,
我想我正在用水平面板或其他东西失去虚拟化能力.
i guess that i am loosing the virtisalization with horizontal panel or something ....
欢迎提出任何想法或帮助.
any idea or help is welcome .
谢谢!
推荐答案
>>>我想我正在用水平面板之类的东西来简化虚拟化. ...
是的,尝试使用VirtualizingStackPanel:
Yes, try to use a VirtualizingStackPanel:
<ItemsPanelTemplate>
<VirtualizingStackPanel Orientation="Horizontal" Width="1000" IsItemsHost="True" />
</ItemsPanelTemplate>
WrapPanel没有UI虚拟化功能.
A WrapPanel has no UI virtualization functionality.
希望有帮助.
请记住,通过将有用的帖子标记为答案来关闭话题,然后在遇到新问题时开始新话题.请不要在同一线程中问几个问题.
Please remember to close your threads by marking helpful posts as answer and then start a new thread if you have a new question. Please don't ask several questions in the same thread.
这篇关于列表框分组和ItemsPanel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!