1

I use the MVVMLight EventToCommand to hook up a command to the MouseEnter event:

<i:Interaction.Triggers>
    <i:EventTrigger EventName="MouseEnter">
        <GalaSoft_MvvmLight_Command:EventToCommand Command="{Binding DragHandleMouseEnterCommand}"  />
    </i:EventTrigger>
</i:Interaction.Triggers>  

How do I unhook the handler programatically?
viewObject.MouseEnter -= viewObject.GetViewModel().DragHandleMouseEtnerCommand gives a type mismatch error.

UPDATE: Looks like I need to use the viewObject.Triggers collection, somehow. Suggestions...?
UPDATE II: Nope, nothing in the Triggers collection....

Thanks for any insight...

Number8
  • 12,322
  • 10
  • 44
  • 69

1 Answers1

1

Why not simply set DragHandleMouseEnterCommand to null in your viewmodel?

The trigger would remain but it wouldn't fire anything. If you wanted to reactivate the Command you'd just need to "new up" a new one and bind it to the property and call RaisePropertyChanged("DragHandleMouseEnterCommand").

Faster Solutions
  • 7,005
  • 3
  • 29
  • 45
  • Good idea -- thanks for the reply. Unfortunately, something else is still going on. The Command is not called after setting it to null (obviously), but the cursor is still being changed. This question is related: http://goo.gl/VQoe3 – Number8 Oct 30 '12 at 17:57
  • FS: Not sure what code would be useful. We have a property in the ViewModel (WaitMode); when it is set to true, we set the RelayCommand to null, and create a new RelayCommand when WaitMode is set to false. – Number8 Oct 30 '12 at 23:31