2

I want to implement a function that using a ListView to load items, but the number of items are very large, so I want when the user scroll the scrollbar to the end of the ListView, it auto load more items. I have found a solution to detect if the scroll is scrolled to the end here: Detect when WPF listview scrollbar is at the bottom? But in MVVM, I didn't find a solution to pass EventArgs. Is there any other solutions? My Xaml looks like this:

<ScrollViewer>
<ListView>
    ...
</ListView>
</ScrollViewer>

Thanks!

Community
  • 1
  • 1
Allen4Tech
  • 2,094
  • 3
  • 26
  • 66
  • repeat question: http://stackoverflow.com/questions/1301411/detect-when-wpf-listview-scrollbar-is-at-the-bottom – Andrew Aug 14 '13 at 07:24
  • 1
    I have read that thread. Please read my question, I want to do that with MVVM, but I don't know how to pass EventArgs. – Allen4Tech Aug 15 '13 at 05:48

2 Answers2

0

You could have your View execute an ICommand Property on your ViewModel and take advantage of the CommandParameter parameter of the Execute method. However, I would warn that passing the state of your View to the ViewModel so that the ViewModel can determine which items to load is not an appropriate MVVM pattern. Generally, the ViewModel needs to drive the show, even if that includes offloading some UI state information from the View to the ViewModel so that it can natively deduce what to load.

Andrew
  • 1,482
  • 9
  • 16
  • Why does it have to be an EventArgs object? Is the point not just to pass some state from the View to the ViewModel? The CommandParameter is of type Object - so, in fact, you could pass EventArgs. – Andrew Aug 15 '13 at 07:01
0

If you use MVVMLight in your WPF project, just set PassEventArgsToCommand true.

eg:

xmlns:ni="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:mv="http://www.galasoft.ch/mvvmlight"

<ni:Interaction.Triggers>
<ni:EventTrigger EventName="SelectionChanged">
    <mv:EventToCommand Command="{Binding YourCommand}" PassEventArgsToCommand="True" />
</ni:EventTrigger>

Laban Liao
  • 19
  • 6