I have a scrollviewer in my WPF project. Inside the scrollviewer there are several buttons with images in the inside. Something similar to Popcorn Time (image).
There can be a lot of buttons inside the scrollviewer so it can get quite slow.
My question is, if there is an event or something similar that allows me to know what buttons are currently appearing inside the scrollviewer that the user can see, so at that moment I can load the image of the button and when it goes out of sight I can remove the image to keep the memory consumption and speed of my program a lot better. Thank you.
What I've inquired so far: There is a way to tell if a control is in sight with this method:
private bool IsUserVisible(FrameworkElement element, FrameworkElement container)
{
if (!element.IsVisible)
return false;
Rect bounds = element.TransformToAncestor(container).TransformBounds(new Rect(0.0, 0.0, element.ActualWidth, element.ActualHeight));
Rect rect = new Rect(0.0, 0.0, container.ActualWidth, container.ActualHeight);
return rect.Contains(bounds.TopLeft) || rect.Contains(bounds.BottomRight);
}
If I just knew of an event that can help me using this at the moment I need, that would be great. Thanks a lot.