Sure - here are two ways for you to consider.
Option 1
Prism's documentation has a section on "Making a command globally available" using their CompositeCommand class. To do this, create a public static class in a common library that both assemblies can reference:
public static class GlobalCommands
{
public static CompositeCommand ShowFinanceFormCommand = new CompositeCommand();
}
In the Finance form viewmodel, you would register your actual command (which has all the logic for showing the form) with:
public FinanceViewModel()
{
GlobalCommands.ShowFinanceFormCommand.RegisterCommand(this.ShowFinancePopupCommand);
}
In the employee view model, bind your button's ICommand
to the ShowFinanceFormCommand
composite command.
public EmployeeViewModel()
{
this.EmployeeShowFinanceFormCommand = GlobalCommands.ShowFinanceFormCommand;
}
Option 2
If you need to broadcast events across modules in a loosely coupled fashion, use Prism's EventAggregator class. To implement this, create a ShowFinanceFormEvent
in a common assembly that both can reference. In the employee viewmodel, publish an event when the button is pressed. In the finance viewmodel, subscribe to that event and react accordingly.
public class ShowFinanceFormEvent : PubSubEvent<object>
{
}
public class EmployeeViewModel
{
private readonly IEventAggregator eventAggregator;
public EmployeeViewModel(IEventAggregator eventAggregator)
{
this.ShowFormCommand = new DelegateCommand(RaiseShowFormEvent);
this.eventAggregator = eventAggregator;
}
public ICommand ShowFormCommand { get; }
private void RaiseShowFormEvent()
{
this.eventAggregator.GetEvent<ShowFinanceFormEvent>().Publish(null);
}
}
public class FinanceViewModel
{
public FinanceViewModel(IEventAggregator eventAggregator)
{
eventAggregator.GetEvent<ShowFinanceFormEvent>().Subscribe(this.ShowForm);
this.ShowFinanceFormRequest = new InteractionRequest<INotification>();
}
public InteractionRequest<INotification> ShowFinanceFormRequest { get; }
private void ShowForm(object src)
{
this.ShowFinanceFormRequest.Raise(
new Notification { Content = "Wow it worked", Title = "Finance form title" });
}
}