WPF - Virtualising WrapPanel

北战南征 提交于 2019-12-20 02:47:15

问题


does anyone have a functioning virtualising WrapPanel I can use in a WPF application?

I have downloaded and tried the implementation at http://virtualwrappanel.codeplex.com/. However, I get the following exception:

"Layout measurement override of element 'MyNamespace.VirtualizingWrapPanel' should not return PositiveInfinity as its DesiredSize, even if Infinity is passed in as available size."

This is when trying to apply the wrappanel to a ListBox


回答1:


This is probably a bug that you might be able to fix yourself. Look for the MeasureOverride method. It always seem to return the availableSize wich was passed to the method. As the exception states you must not return availableSize when it contains double.PositiveInfinity. So try this:

if(availableSize.Width == double.PositiveInfinity || availableSize.Height == double.PositiveInfinity)
{
    return Size.Empty;
}

// all the measureoverride code comes here

return availableSize;

I haven't looked at the implementation in details. But who knows, you might be able to get a away with this if the panel doesn't save state between MeasureOverride and ArrangeOverride (wich it shouldn't if it is well implemented).




回答2:


That problem is probably occuring because you have your listbox inside another control, such as a stack panel or scroll viewer, which allows the listbox to grow to whatever size it likes. While the virtual wrap panel shouldn't give an error in this case, it does explain the performance problem.

Even using one of Microsoft's own virtualising panels won't fix the performance issues in this case because the virtualisation is defeated. Since the listbox can grow to whatever size it likes, it does so and draws all the items even if they're not on screen... hence the virtualisation doesn't apply.

If you ensure your listbox isn't inside one of these sorts of containers, you should find the virtualisation starts working performance improves significantly.



来源:https://stackoverflow.com/questions/3736989/wpf-virtualising-wrappanel

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!