WrapPanel:内存不足 [英] WrapPanel : OutOfMemory

查看:109
本文介绍了WrapPanel:内存不足的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

当我在包装面板中添加1000多个项目时,我得到一个System.OutOfMemoryException.
我添加的项目是一个包含位图的用户控件.

这是我的WrapPanel的定义:

Hello,

I get an System.OutOfMemoryException when i add more than 1000 items in a wrappanel.
The items i add is a usercontrol contening a bitmap. 

Here is the definition of my WrapPanel :

<Style TargetType="{x:Type ListBox}" x:Key="PhotoListBoxStyle">



<Setter Property="Foreground" Value="White" />



<Setter Property="Template">



<Setter.Value>



<ControlTemplate TargetType="{x:Type ListBox}" >



<WrapPanel Margin="5" IsItemsHost="True" Orientation="Horizontal" 



ItemHeight="{Binding ElementName=sldZoom, Path='Value'}" 



ItemWidth="{Binding ElementName=sldZoom, Path='Value'}" 



VerticalAlignment="Top" HorizontalAlignment="Stretch" 



VirtualizingStackPanel.IsVirtualizing="True" VirtualizingStackPanel.VirtualizationMode="Recycling"



ScrollViewer.IsDeferredScrollingEnabled="True" ScrollViewer.CanContentScroll="True"/>



</ControlTemplate>



</Setter.Value>



</Setter>



<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Disabled"></Setter>



</Style>



推荐答案

您遇到了内存不足异常,因为您正在尝试渲染1000位图图像...那里没有震撼...不幸的是,有一些关于将东西放入经常破坏虚拟化的ListBoxes/ListViews中...我现在实际上正面临着相同的问题,并且即将发布类似的问题.

我不确定添加虚拟化的方法是否可以使用,但是,我发现了这篇有关如何创建虚拟化WrapPanel的文章:

http://jerryclin .wordpress.com/2008/02/06/making-a-virtualizing-wrappanel/

我还没有尝试过,但是考虑到您要尝试做的事,我会说给它一个继续...不会再糟了:-p

希望这会有所帮助,
Aj
You get an out of memory exception because you're trying to render 1000 bitmap images...no shock there...unfortunately there's something about putting stuff inside ListBoxes/ListViews that frequently breaks virtualization...I'm actually facing the same issue right now and am about to post a similar question. 

I'm not sure the method by which you added virtualization will work, however, I found this article on how to create a Virtualizing WrapPanel:

http://jerryclin.wordpress.com/2008/02/06/making-a-virtualizing-wrappanel/

I've not tried it out, but considering what you're trying to do I would say give it a go...couldn't be any worse :-p

Hope this helps,
Aj


这篇关于WrapPanel:内存不足的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆