I define my ListBox like this in XAML:
<ListBox Name="myListBox"
HorizontalContentAlignment="Stretch"
ScrollViewer.HorizontalScrollBarVisibility="Hidden"
ScrollViewer.ScrollChanged="OnScrollChanged" <- I want to create onScrollChanged event
Grid.Row="0">
...
</ListBox>
Then in my cs file, I define this event:
private void OnScrollChanged(object sender, ScrollChangedEventArgs e)
{
var scrollViewer = (ScrollViewer)sender; //ERROR
if (scrollViewer.VerticalOffset == scrollViewer.ScrollableHeight)
MessageBox.Show("This is the end");
}
I am trying to detect when user scrolls to the very bottom of ListBox. But I get error that ListBox cannot be casted to Scrollviewer. How do I get the scrollviewer?
Thanks