0
votes

I am trying to bind to the "scrolled" event from the CollectionView control in a Xamarin forms API using the mvvmcross framework. I have found Documentation that MvxEventNameTargetBinding should work but no example on how. So I am binding the event using the fluent api in the View

set.Bind(CardCollectionView).For(v => v.ItemsSource).To(vm => vm.Cards).OneWay();
set.Bind(CardCollectionView).For("Scrolled").To(vm => vm.CardDetailScrollPositionChanged);

and the model has the Following API:

public IMvxCommand<EventArgs> CardDetailScrollPositionChanged { get; private set; }
   ...
CardDetailScrollPositionChanged = new MvxAsyncCommand<EventArgs>(async (EventArgs arg) => CardScrolledFunction(arg));
   ...
private async Task CardScrolledFunction(EventArgs args)
    {
        ...
    }

The code above can works in the way that the collection view is getting data from the model. Can any one please point out to me how to access the EventArgs following the mvvmCross framework using the fluent API so that my model knows what is the current visible item?

Thanks HP

1

1 Answers

0
votes

I don't know how to do this with the fluent API and I'm not sure what CardCollectionView is. I guess it's your custom CollectionView class? What you could try is adding a method to the Scrolled EventHandler.

So in your view:

var viewModel = ViewModel as YourViewModelHere;
CardCollectionView.Scrolled += viewModel.CardDetailScrollPositionChanged;

and in your view model:

public void CardDetailScrollPositionChanged(object sender, EventArgs e)
{
    ...
}