How to implement the functionality will mainly depend on your personal preferences and the requirements of your scenario.
In my opinion, a possible approach could be to implement a shared service (lets call it "ViewCountService") which could simply hold a
Dictionary of string - int and subscribe to events through the
When a view is created you can inject the EventAggregator and then:
- When a view is loaded, publish an event (for example ViewOpened
event) with a string payload used to identify the module. (You can know when a view is loaded through its
- When a view is unloaded, publish an event (for example ViewClosed
event) with the aforementioned string. (You can know when a view is unloaded through its
The ViewCountService would subscribe to both events (through the
EventAggregator) and increase / decrease the count associated with the string "identifier," which in this case would identify the module. Then, when you need to know the amount of opened views, you could simply consume this service.
You can find more information about shared services and the
EventAggregator in the following chapter of the Prism documentation:
I hope you find this useful,