简体   繁体   中英

MVVMLight EventToCommand and passing event arguments

I have a mousewheel interactivity trigger on a StackPanel:

 <i:Interaction.Triggers>
         <i:EventTrigger EventName="MouseWheel">
               <cmd:EventToCommand Command="{Binding DataContext.PreviousWeekCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}}"
                                             PassEventArgsToCommand="True"/>
         </i:EventTrigger>
</i:Interaction.Triggers>

and it works great with the PreviousWeekCommand as follows (snippet):

_previousWeekCommand = new RelayCommand<object>(param => ShiftDays(-7), param => (true));

The PassEventArgsToCommand is there because I'm trying to switch this to a different command that will detect if the user has scrolled up or down. The problem is, after a lot of searching, I still can't figure out how to structure the command to deal with the args. Here's what I have, but it doesn't work:

_scrollWheelCommand = new RelayCommand<MouseEventArgs>(ScrollWheel, can => true);

and then this is the ScrollWheel declaration:

public void ScrollWheel(MouseEventArgs args)

Problem is, I never get to this method when I breakpoint it. I also don't know if I'm routing the arguments in the correct way.

EDIT: Oh, and I get no errors.

Try using MouseWheelEventArgs instead of MouseEventArgs when declaring your RelayCommand . The Parameter type should match the event in order for that to work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM