Attaching a command to ScrollViewer.ScrollChanged from a ListView

The WPF ListView class can be configured to automatically handle scrolling without an external ScrollViewer and allows you to register an event handler for the internal scroll control panel by writing XAML, for example:

 <ListView ScrollViewer.ScrollChanged="ScrollChanged" /> 

How to connect it to the MVVM light command? I tried the following, but it does not work:

 <ListView> <i:Interaction.Triggers> <i:EventTrigger EventName="ScrollViewer.ScrollChangedEvent"> <cmd:EventToCommand Command="{Binding ScrollCommand}" /> </i:EventTrigger> </i:Interaction.Triggers> </ListView> 

Note: ScrollCommand is a RelayCommand from my view model.

+6
source share
2 answers

EventTrigger does not EventTrigger for routed events. You can use the solution suggested in this article to create the RoutedEventTrigger class and use it instead of EventTrigger .

+3
source

I recommend behavior for this. If you do not have Blend, you need to get the Blend SDK. But once you do, you can follow this guide to expand the behavior of ScrollViewer.

0
source

Source: https://habr.com/ru/post/921670/


All Articles