In a MVVM/WPF environment, I want to invoke a command (ComputeCommand
) on the ViewModel when the SelectionChanged
event of a ListView is raised. How can this be done, either in XAML or in C#?
Here is my command class. I have tried MainViewModel.Instance.MyCommand.Execute();
in the codebehind, but it's doesn't accept that.
public class ComputeCommand : ICommand
{
public ComputeCommand(Action updateReport)
{
_executeMethod = updateReport;
}
Action _executeMethod;
public bool CanExecute(object parameter)
{
return true;
}
public event EventHandler CanExecuteChanged;
public void Execute(object parameter)
{
_executeMethod.Invoke();
}
}