如何使用 Prism 框架将命令绑定到 WPF 中的按钮

How to bind command to button in WPF using Prism framework

我正在尝试将 WPF 中的单击按钮事件绑定到视图模型中定义的命令,这是我目前的做法:

在 xaml 代码中:

 <Grid>
    <Button Content="Module A" Background="Green" FontWeight="Bold">
        <i:Interaction.Triggers>
            <i:EventTrigger EventName="click">
                <i:InvokeCommandAction Command="{Binding ChargeModuleDCommand}"/>
            </i:EventTrigger>
        </i:Interaction.Triggers>
    </Button>
</Grid>

并且在 ViewModel class 中:

class ModuleAViewModel
{

    public DelegateCommand<object> ChargeModuleDCommand { get; set; }

    public ModuleAViewModel()
    {
        ChargeModuleDCommand = new DelegateCommand<object>(LaunchDModule);
    }

    private void LaunchDModule(object parm)
    {
        Console.WriteLine("I am in the function");
    }
}

但它不起作用。我已尝试按照此问题中的说明进行操作:How to trigger ViewModel command for a specific button events 但它也不起作用。 有什么方法可以让它发挥作用吗?

<Button 
    Command="{Binding ChargeModuleDCommand}" 
    Content="Module A" 
    Background="Green" 
    FontWeight="Bold"
    />

如果 ModuleAViewModel 是 Button 的 DataContext(实际上它本身就是一大堆蠕虫病毒),那应该可行。