- Nir Hasson
- Posts: 71
- Joined:
- Contact:
How to detect if a list box item is visible?
Using Noesis 3.0.9 on Unity.
How can I know if specific list box item is currently visible to the user? (I.E being actually rendered on the screen)
How can I know if specific list box item is currently visible to the user? (I.E being actually rendered on the screen)
-
sfernandez
Site Admin
- Posts: 2983
- Joined:
Re: How to detect if a list box item is visible?
Assuming you can get access to both the ListBox and ListBoxItem, you just need to compare their content bounds:
Does that work for you?
Code: Select all
private bool IsElementVisible(FrameworkElement element, FrameworkElement container)
{
if (element == null || container == null || !element.IsVisible || !element.IsDescendantOf(container))
return false;
Rect elementBounds = element.TransformToAncestor(container).TransformBounds(new Rect(0.0, 0.0, element.ActualWidth, element.ActualHeight));
Rect containerBounds = new Rect(0.0, 0.0, container.ActualWidth, container.ActualHeight);
return containerBounds.IntersectsWith(elementBounds);
}
- Nir Hasson
- Posts: 71
- Joined:
- Contact:
Re: How to detect if a list box item is visible?
That seems to work perfectly, thanks!
I've used the scroll viewer offset approach before but it didn't feel like the right solution.
I've used the scroll viewer offset approach before but it didn't feel like the right solution.
-
sfernandez
Site Admin
- Posts: 2983
- Joined:
Re: How to detect if a list box item is visible?
Great, marking it as solved.
Who is online
Users browsing this forum: Google [Bot] and 90 guests