Depending on how it's being used, you could declare the CompositeCommand as an exported class. Then each view model could import the CompositeCommand and register it's own command.
[Export]
public class SaveWidgetsCompositeCommand : CompositeCommand { }
[Export]
public class FrontWidgetViewModel
{
DelegateCommand FrontSaveCommand { get; set; }
[ImportingConstructor]
public FrontWidgetViewModel( SaveWidgetsCompositeCommand saveCommand)
{
saveCommand.RegisterCommand(FrontSaveCommand);
}
}
[Export]
public class BackWidgetViewModel
{
DelegateCommand BackSaveCommand { get; set; }
[ImportingConstructor]
public BackWidgetViewModel(SaveWidgetsCompositeCommand saveCommand)
{
saveCommand.RegisterCommand(BackSaveCommand);
}
}
If you want to do it with a CompositeCommand via the view, the CompositeCommand would need to be declared in the view and it would need to register the two commands from the view models on binding/instantiation.
As a note, this approach may also require unregistering the view model commands to avoid leaks.