Silverlight Get REAL Visible Items in a Container (WrapPanel)





0/5 (0 vote)
Using this you can animate or change states of the actually visible items
In my case I have to change the state of just a few elements that are visible or partially visible of a big list in a wrappanel and I cannot force to animate 100 items instead of 12. So here is a way to make this:
<ScrollViewer x:Name="ScrollContainer" >
<toolkit:WrapPanel x:Name="WrappedButtons"/>
</ScrollViewer>
and the c#
UIElement MyUIE = ScrollContainer; GeneralTransform gt = MyUIE.TransformToVisual(Application.Current.RootVisual as UIElement); Rect rect = new Rect(gt.Transform(new Point(0, 0)), MyUIE.RenderSize); var foundElements = VisualTreeHelper.FindElementsInHostCoordinates(rect, MyUIE); Type MyType = typeof(Button); if (foundElements != null) { var listBoxItem = foundElements.Where(w => w.GetType().Equals(MyType)).ToList(); TBResult.Text = listBoxItem != null ? listBoxItem.Count.ToString() : String.Empty; }And that's all try it, It successfully works. (Of course as many tips is a mix and changes of stuffs from the internet)