How can I force a ListView with a custom panel to re-measure when the ListView width goes below the

Posted by Scott Whitlock on Stack Overflow See other posts from Stack Overflow or by Scott Whitlock
Published on 2010-05-26T04:09:56Z Indexed on 2010/05/26 4:21 UTC
Read the original article Hit count: 305

Filed under:
|
|

Sorry for the long winded question (I'm including background here). If you just want the question, go to the end.

I have a ListView with a custom Panel implementation that I'm using to implement something similar to a WrapPanel, but not quite.

I'm overriding the MeasureOverride and ArrangeOverride methods in the custom panel.

If I do the naive implementation of a WrapPanel in the MeasureOverride method it doesn't work when the ListView is resized. Let's say the custom panel does a measure and the constraint is a width of 100 and let's say I have 3 items that are 40 wide each. The naive approach is to return a size of 80,80 but when I resize the window that the ListView is in, down to say 75, it just turns on the horizontal scrollbar and never calls measure or arrange again (it does keep measuring and arranging if the width is greater than 80).

To get around this, I hard coded the measurement to only have a width of the widest item. Then in the arrange, it gives me more space than I asked for and I use as much horizontal space as I can before wrapping. If I resize the window smaller than the smallest item in the ListView, then it turns on the scrollbar, which is great.

Unfortunately this is causing a big problem when I have one of these ListViews with a custom panel nested inside of another one. The outside one works ok, but I can't get the inside one to "take as much as it needs". It always sizes to the smallest item, and the only way around it is to set the MinWidth to be something greater than zero.

Anyway, stepping back for a second, I think the real way to fix this is to go back to the Naive implementation of the WrapPanel but force it to re-measure when the ListView width goes below the Size I previously returned as a measurement. That should solve my problem with the nested one.

So, that's my question:

  • I have a ListView with a custom panel
  • If I return a measurement width on the panel and the ListView is resized to less than that width, it stops calling MeasureOverride
  • How can I get it to continue calling MeasureOverride?

© Stack Overflow or respective owner

Related posts about wpf

Related posts about listview