2016-04-15 73 views
1

我有一個組合框,我需要一個命令在我的視圖模型中綁定到它的ContextMenuOpening事件。我試過引用System.Windows.Interactivity並使用InvokeCommandAction,但該命令沒有調用。有沒有人看到我要去哪裏錯了?InvokeCommandAction not calling

<ComboBox x:Name="comboBoxAssets" Grid.Column="0" VerticalAlignment="Top" Margin="928,62,0,0" Height="25" 
      ItemsSource="{Binding Source={StaticResource SortedAssets}}" 
      SelectedItem="{Binding Path=Assets, UpdateSourceTrigger=PropertyChanged}" 
      Style="{StaticResource ComboBoxDefault}" HorizontalAlignment="Left" Width="212" > 

    <i:Interaction.Triggers> 
     <i:EventTrigger EventName="ContextMenuOpening">  

      <i:InvokeCommandAction Command="{Binding ContextMenuOpeningCommand, Mode=OneWay}" /> 

     </i:EventTrigger> 
    </i:Interaction.Triggers> 
</ComboBox> 

視圖模型:

public ICommand ContextMenuOpeningCommand 
{ 
    get 
    { 
     if (_contextMenuOpeningCommand == null) 
     { 
      _contextMenuOpeningCommand = new RelayCommand<object>(param => this.ContextMenuOpening(), 
       null); 
     } 

     return _contextMenuOpeningCommand; 
    } 
} 

public void ContextMenuOpening() 
{ 
    System.Windows.MessageBox.Show("test", "test"); 
} 

private ICommand _contextMenuOpeningCommand; 
+1

你試過不同的事件?也許DropDownOpened看看命令是否被擊中。我試了一下,它在這裏工作,唯一的區別是我使用了DelegateCommand,但這不應該。 – adminSoftDK

+0

是的!而已。非常感謝您的幫助。如果您將此添加爲答案,我會很樂意將其標記爲這樣。 – fyodorfranz

回答

1

請儘量DropDownOpened看命令是否被擊中。我試過了,它在這裏工作。希望這有助於:)