0

I followed this link Detect when WPF listview scrollbar is at the bottom?
But ScrollBar.Scroll doesn't exist for ListView in Windows 10 .. how to achieve this requirement in windows 10

Thanks

Community
  • 1
  • 1
djkpA
  • 1,224
  • 2
  • 27
  • 57

3 Answers3

0

Use the methods described here How can I detect reaching the end of a ScrollViewer item (Windows 8)?

If you want incremental loading there's a built-in solution for that. Otherwise go and traverse the visual tree for the scrollviewer object in the template.

Community
  • 1
  • 1
Tamás Deme
  • 2,194
  • 2
  • 13
  • 31
0

You can do it by simply detecting VerticalOffset and ScrollableHeight of your ScrollViewer. Here is my simple code.

XAML:

<!--Apply ScrollViwer over the ListView to detect scrolling-->
<ScrollViewer Name="ContentCommentScroll" Grid.Row="2"
              ViewChanged="ContentCommentScroll_ViewChanged" ScrollViewer.VerticalScrollBarVisibility="Auto"
              ScrollViewer.HorizontalScrollMode="Disabled" ScrollViewer.HorizontalScrollBarVisibility="Disabled">

                <!--My Dynamic ListView-->
               <ListView Name="MyDataList" ItemsSource="{Binding MyList}" 
                            ItemTemplate="{StaticResource MyDataTemplate}"
                            ItemContainerStyle="{StaticResource myStyle}"/>
</ScrollViewer>

And code in its XAML.CS:

// Hold ScrollViwer
public ScrollViewer listScrollviewer = new ScrollViewer();

// Binded event, which will trigger on scrolling of ScrollViewer
private void ContentCommentScroll_ViewChanged(object sender, ScrollViewerViewChangedEventArgs e)
{
    Scrolling(ContentCommentScroll);
}

private void Scrolling(DependencyObject depObj)
{
    ScrollViewer myScroll= GetScrollViewer(depObj);

    // Detecting if ScrollViewer is fully vertically scrolled or not
    if (myScroll.VerticalOffset ==  myScroll.ScrollableHeight)
    {
        // ListView reached at of its end, when you are scrolling it vertically.
        // Do your work here here 
    }
}

public static ScrollViewer GetScrollViewer(DependencyObject depObj)
{
    if (depObj is ScrollViewer) return depObj as ScrollViewer;

    for (int i = 0; i < VisualTreeHelper.GetChildrenCount(depObj); i++)
    {
        var child = VisualTreeHelper.GetChild(depObj, i);

        var result = GetScrollViewer(child);
        if (result != null) return result;
    }
    return null;
}

You can also apply similar logic to detect that if ListView Horizontally reached to its end.

Arsman Ahmad
  • 2,000
  • 1
  • 26
  • 34
-1

You can wrap it with a ScrollViewer and name it. Then you can use some other methods.