7

The WPF ListView class can be set up to automatically handle scrolling without an external ScrollViewer and it's possible to register an event handler for the control's internal scrollbar by writing XAML like such:

<ListView ScrollViewer.ScrollChanged="ScrollChanged"  />

How to attach it to MVVM light Command? I tried the following, but it doesn't 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 viewmodel.

Adi Lester
  • 24,731
  • 12
  • 95
  • 110
ISens
  • 191
  • 2
  • 11

2 Answers2

3

EventTrigger doesn't trigger for routed events. You can use the solution proposed in this article to create a RoutedEventTrigger class and use it instead of EventTrigger.

Adi Lester
  • 24,731
  • 12
  • 95
  • 110
  • thanks, it's very useful, but now I have another problem : I can't get any args from it. – ISens Jul 30 '12 at 15:04
0

I recommend a Behavior for this. If you don't have Blend, you'll need to get the Blend SDK. But once you have that, you can follow this tutorial to extend the behavior of the ScrollViewer.

Thelonias
  • 2,918
  • 3
  • 29
  • 63
  • You're using *a* behavior, the EventToCommand behavior. But you can write a custom one that searches for the ListView's ScrollViewer and hooks up to the "ScrolledChanged" event. You can also add a DependencyProperty on the behavior that allows you to bind a command. In the event handler you can invoke the command you're binding to. – Thelonias Jul 30 '12 at 13:53