Diese Methode ermittelt wann der ScrollViewer am Ende einer ListBox ist.
Namespace:System.Window.Media.Visual
XAML
<ListBox ScrollViewer.ScrollChanged="c_listBox_ScrollChanged"/>
private void c_listBox_ScrollChanged(object sender, ScrollChangedEventArgs e)
{
ScrollViewer viewer = GetDescendantByType(BoxedListBox, typeof(ScrollViewer)) as ScrollViewer;
if (viewer.VerticalOffset == viewer.ScrollableHeight)
{ }
}
public Visual GetDescendantByType(Visual element, Type type)
{
if (element == null) return null;
if (element.GetType() == type) return element;
Visual foundElement = null;
if (element is FrameworkElement)
{
(element as FrameworkElement).ApplyTemplate();
}
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(element); i++)
{
Visual visual = VisualTreeHelper.GetChild(element, i) as Visual;
foundElement = GetDescendantByType(visual, type);
if (foundElement != null)
break;
}
return foundElement;
}
3 Kommentare zum Snippet