ISens
ISens

Reputation: 191

Attaching Command to ScrollViewer.ScrollChanged of ListView

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.

Upvotes: 7

Views: 5110

Answers (2)

Adi Lester
Adi Lester

Reputation: 25201

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.

Upvotes: 3

Thelonias
Thelonias

Reputation: 2935

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.

Upvotes: 0

Related Questions