Search code examples
c#catel

Catel InterestedIn OnViewModelCommandExecuted check which command executed


I use the Catel 4.3.0 framework.

I've decorated one of my ViewModels with

[InterestedIn(typeof(AddSupplierWindowViewModel))]

and added

protected override void OnViewModelCommandExecuted(IViewModel viewModel, 
                        ICatelCommand command, object commandParameter)

This event fires correctly.

In the AddSupplierWindowViewModel I've multiple commands, but only the CmdAddSupplier is of interest to this viewmodel.

So I want to check if this command is fired, but I can't figure out how to test for it.

I expect something like

command.Name == "CmdAddSupplier" 

but I can't find something like this.

Could someone provide an example of how to test for this.

Kind regards

Jeroen


Solution

  • We recommend to use CommandContainers instead of view models to host commands that span more than 1 view model. The InterestedIn communication will probably (most likely) be removed from Catel in v5.

    Some good examples can be found in the Orchestra repository.

    If you really want to keep using the InterestedIn (which is actually a shortcut for setting up services to take care of the communication between the view models), you'll need to figure out how to retrieve the instance (you only get an instance of a command) to a command name. For example, you could use the Tag property on the command.