How to invalidate layout of listbox from custom children
Posted
by Stephen Price
on Stack Overflow
See other posts from Stack Overflow
or by Stephen Price
Published on 2010-03-22T06:06:21Z
Indexed on
2010/03/22
6:11 UTC
Read the original article
Hit count: 400
wpf
|wpf-controls
I have a custom panel for a listbox
<ItemsPanelTemplate x:Key="FloatPanelTemplate">
<Controls:FloatPanel x:Name="CardPanel" />
</ItemsPanelTemplate>
The panel lays out its children using its X and Y dependency properties. This all works nicely when the FloatPanel is used by itself - I'm using FrameworkPropertyMetadataOptions.AffectsArrange | FrameworkPropertyMetadataOptions.AffectsMeasure on the dependency properties of the child items to tell the FloatPanel to redraw its layout.
When I use it in a Listbox (code above) then it draws fine the first time, but when I drag the children (which modifies the item's X and Y) it is not notifying the Listbox that it needs to redraw the FloatPanel's children. I think the issue is related to the fact that each item in the bound collection is wrapped with a ListBoxItem.
Hopefully I've described what i'm doing well enough that someone can tell me how to make the panel (or its children) tell it needs to do the Layout routines again. As I said it works once (initial draw) but then dragging items doesn't work (Listbox isnt aware that its children have changed and needs to relayout.) If I drag an item and then resize the window, the listbox does a layout and the items are drawn in their new locations.
How do I notify the ListBox (or more importantly the FloatPanel in the ItemsPanelTemplate) that it needs to do a Layout pass?
© Stack Overflow or respective owner