c# – 将WrapPanel虚拟化为ListView的ItemsTemplate

c# – 将WrapPanel虚拟化为ListView的ItemsTemplate,第1张

概述我的窗口中有一个ListView. ListView的默认ItemsPanel已替换为WrapPanel.我还有一个DataTemplate,它的ListViewItems.在运行时,主窗口将不会响应一段时间,因为ListView具有超过700(并且不断增加)ListViewItems(来自数据绑定).有没有办法让主窗口保持响应? 可选:当ListView没有准备好时,我希望在ListView上显 我的窗口中有一个ListVIEw. ListVIEw的默认ItemsPanel已替换为WrapPanel.我还有一个DataTemplate,它的ListVIEwItems.在运行时,主窗口将不会响应一段时间,因为ListVIEw具有超过700(并且不断增加)ListVIEwItems(来自数据绑定).有没有办法让主窗口保持响应?

可选:当ListVIEw没有准备好时,我希望在ListVIEw上显示一个文本(或可能的Progressbar)并说出“Please Wait …”或“Loading Items …”之类的内容.

XAML:

<ListVIEw x:name="MyListVIEw" VirtualizingPanel.IsVirtualizing="True" VirtualizingPanel.VirtualizationMode="Recycling" HorizontalAlignment="left"  Height="577" VerticalAlignment="top" WIDth="902" ScrollVIEwer.HorizontalScrollbarVisibility="auto" Foreground="Black" margin="10,10,0" ScrollVIEwer.CanContentScroll="True" borderBrush="#FFC54B4B" borderThickness="3" Background="White">                    <ListVIEw.ItemsPanel>                        <ItemsPanelTemplate>                            <WrapPanel MaxWIDth="{Binding (FrameworkElement.ActualWIDth),relativeSource={relativeSource AncestorType=ScrollContentPresenter}}"                                ItemWIDth="{Binding (ListVIEw.VIEw).ItemWIDth,relativeSource={relativeSource AncestorType=ListVIEw}}"                                MinWIDth="{Binding ItemWIDth,relativeSource={relativeSource Self}}"                                ItemHeight="{Binding (ListVIEw.VIEw).ItemHeight,relativeSource={relativeSource AncestorType=ListVIEw}}" />                        </ItemsPanelTemplate>                    </ListVIEw.ItemsPanel></ListVIEw>

编辑:

我试过这个:

List<something> MyList = new List<something>(); ThreadPool.QueueUserWorkItem(_ =>      {          ( Create MyList here...)          dispatcher.BeginInvoke(new Action(() =>          {              MyListVIEw.ItemsSource = MyList;          }));      });

在ListVIEw准备好之前,主窗口仍然没有响应.

解决方法 您使用无法进行UI虚拟化的面板(WrapPanel)(与默认ListVIEw ItemPanel模板中使用的VirtualizingStackPanel不同).这意味着你所有的物品都被渲染,即使是那些目前看不到的物品.据我所知,WPF没有内置的虚拟化包装面板,所以你可以尝试一些免费的虚拟化包装面板(例如- http://virtualwrappanel.codeplex.com/),但我不能说它们有多好,我使用Telerik的版本不是免费的.另一个选项是切换回VirtualizingStackPanel.除此之外,请确保在非UI线程上加载项目(如另一个答案中所述). 总结

以上是内存溢出为你收集整理的c# – 将WrapPanel虚拟化为ListView的ItemsTemplate全部内容,希望文章能够帮你解决c# – 将WrapPanel虚拟化为ListView的ItemsTemplate所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1219708.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-05
下一篇 2022-06-05

发表评论

登录后才能评论

评论列表(0条)

保存