NicolasR NicolasR - 9 months ago 82
C# Question

How to bind command to button in WPF using Prism framework

I am trying to bind a click on button event in WPF to a command defined in a View Model, here is how I am doing that for now :

In the xaml code :

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

and in the 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");

but it does not work. I've tried to do it as specified in this question : How to trigger ViewModel command for a specific button events
but it does not work either.
Is there any way that I can make it work ?

    Command="{Binding ChargeModuleDCommand}" 
    Content="Module A" 

If ModuleAViewModel is the Button's DataContext, that should work.