Any way to know if a UIElement is visible in the window?
Posted: 21 Aug 2019, 21:01
I have a ListView bound to an ObservableCollection of 100s of items, each of which has an associated Noesis.BitmapImage that must be displayed as a thumbnail on the screen. I can't load them all at once or the UI thread pauses for a long time. So, I only want to load the ones that are visible in the screen when scrolling stops.
How do I check if a UIElement is visible? (The IsVisible property returns true even for offscreen elements).
I found the below code somewhere but it uses "TransformBounds" which doesn't appear to be implemented in Noesis...
Thanks.
How do I check if a UIElement is visible? (The IsVisible property returns true even for offscreen elements).
I found the below code somewhere but it uses "TransformBounds" which doesn't appear to be implemented in Noesis...
Code: Select all
public static bool IsUserVisible(this UIElement element)
{
if (!element.IsVisible)
return false;
var container = VisualTreeHelper.GetParent(element) as FrameworkElement;
if (container == null) throw new ArgumentNullException("container");
Rect bounds = element.TransformToAncestor(container).TransformBounds(new Rect(0.0, 0.0, element.RenderSize.Width, element.RenderSize.Height));
Rect rect = new Rect(0, 0, container.ActualWidth, container.ActualHeight);
return rect.IntersectsWith(bounds);
}
Thanks.