Silverlight 4.0 MVVMLight:如何断开事件处理程序

Silverlight 4.0 MVVMLight:如何断开事件处理程序,silverlight-4.0,mvvm-light,eventtocommand,Silverlight 4.0,Mvvm Light,Eventtocommand,我使用MVVMLight EventToCommand将命令连接到MouseEnter事件: <i:Interaction.Triggers> <i:EventTrigger EventName="MouseEnter"> <GalaSoft_MvvmLight_Command:EventToCommand Command="{Binding DragHandleMouseEnterCommand}" /> </i:Ev

我使用MVVMLight EventToCommand将命令连接到MouseEnter事件:

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

如何以编程方式解除挂钩处理程序?
viewObject.MouseEnter-=viewObject.GetViewModel()。DragHandleMouseEtnerCommand给出了类型不匹配错误

<i:Interaction.Triggers>
    <i:EventTrigger EventName="MouseEnter">
        <GalaSoft_MvvmLight_Command:EventToCommand Command="{Binding DragHandleMouseEnterCommand}"  />
    </i:EventTrigger>
</i:Interaction.Triggers>  
更新:看起来我需要使用viewObject.Triggers集合。建议…?
更新二:不,触发器集合中没有

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

感谢您的帮助……

为什么不在viewmodel中将DragHandleMouseEnterCommand设置为null

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

扳机会保持不变,但不会发射任何东西。如果要重新激活该命令,只需“新建”一个新命令并将其绑定到属性,然后调用RaisePropertyChanged(“DragHandleMouseEnterCommand”)。

为什么不在viewmodel中将DragHandleMouseEnterCommand设置为null

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

扳机会保持不变,但不会发射任何东西。如果要重新激活该命令,只需“新建”一个新命令并将其绑定到属性,然后调用RaisePropertyChanged(“DragHandleMouseEnterCommand”)。

好主意——感谢您的回复。不幸的是,其他一些事情仍在发生。将命令设置为null(显然)后不会调用该命令,但光标仍在更改。这个问题是相关的:FS:不确定什么代码会有用。我们在ViewModel(WaitMode)中有一个属性;当设置为true时,我们将RelayCommand设置为null,并在WaitMode设置为false时创建一个新的RelayCommand。好主意——感谢您的回复。不幸的是,其他一些事情仍在发生。将命令设置为null(显然)后不会调用该命令,但光标仍在更改。这个问题是相关的:FS:不确定什么代码会有用。我们在ViewModel(WaitMode)中有一个属性;当设置为true时,我们将RelayCommand设置为null,并在WaitMode设置为false时创建一个新的RelayCommand。
<i:Interaction.Triggers>
    <i:EventTrigger EventName="MouseEnter">
        <GalaSoft_MvvmLight_Command:EventToCommand Command="{Binding DragHandleMouseEnterCommand}"  />
    </i:EventTrigger>
</i:Interaction.Triggers>