I have a stackpanel(vertical orientation) with fixed height, i put in it n children with variable height, how do i remove child elements that are "pushed" out by newly added child.
+1
A:
You need first to work out where relative to the top of the stack panel a child is:-
GeneralTransform gt = aChild.TransformToVisual(theStackPanel);
Point pos = gt.Transform(new Point(0, 0));
You also need the actual height of the Stackpanel:-
Double height = theStackPanel.ActualHeight;
Now if pos.Y > height then the child is beyond bottom edge of the StackPanel.
AnthonyWJones
2010-01-19 21:52:28
this is interesting, however, stack panel actualheight is changing when i add new elements, so pos.Y > height is never true because height grows, it grows beyond its container(in my case grid). solution is to check pos.Y against stackpanels container. Btw. thanks for idea.
BorisT
2010-01-20 16:45:32
I also wanted to add that this will not work the same way with VirtualizingStackPanel objects (like what is used in ListBox) becauase ActualHeight becomes the number of items it can contain, not the number of pixels.
JasonRShaver
2010-01-20 22:24:36
@Boris: interesting that's not my experience in testing. You give your stackpanel a specific height?
AnthonyWJones
2010-01-20 23:47:11
@Anthony: nope,it is not fixed, it is streched in its container.(and fullscreen) container.
BorisT
2010-01-21 11:07:11