Hi,
Here is a method that lets you attach to the "Scroll" event:
Code: Select all
public static void ListenToScrollEvent(ScrollViewer scrollViewer, Action handler)
{
if (scrollViewer.IsLoaded)
{
var div = CSHTML5.Interop.GetDiv(scrollViewer);
CSHTML5.Interop.ExecuteJavaScript(@"
var div = $0;
var handler = $1;
div.addEventListener('scroll', handler, false);
", div, handler);
}
else
{
System.Windows.MessageBox.Show("You must add the ScrollViewer to the visual tree before listening to the Scroll event. For example, call this method from the Page.Loaded event instead.");
}
}
Here is how to test it:
- Put the static method above somewhere in your code
- Define a ScrollViewer in XAML like so:
Code: Select all
<ScrollViewer x:Name="ScrollViewer1" Height="100" Width="20">
<Rectangle Height="300" Width="20"/>
</ScrollViewer>
- Call the following C# code:
Code: Select all
public MainPage()
{
this.InitializeComponent();
this.Loaded += MainPage_Loaded;
}
void MainPage_Loaded(object sender, RoutedEventArgs e)
{
ListenToScrollEvent(ScrollViewer1, () =>
{
System.Windows.MessageBox.Show("Scrolled!");
});
}
You can adapt the code or use similar Interop calls to get the scroll position etc.
Regards,
JS-Support