InvokeCommandAction没有调用

时间:2016-04-15 14:14:21

标签: wpf xaml mvvm blend icommand

我有一个组合框,我需要在我的视图模型中使用一个命令来绑定它的ContextMenuOpening事件。我已经尝试引用System.Windows.Interactivity并使用InvokeCommandAction,但命令没有调用。有谁看到我哪里出错了?

<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 个答案:

答案 0 :(得分:1)

请尝试使用DropDownOpened来查看该命令是否被命中。我尝试了它,它在这里工作。希望这会有所帮助:)