开发者

Composite events in locally scoped regions with Prism (CAL)

I'm starting to train Prism (CAL) with a small application and faced some problems.

I'm creating multiple instances of my MainView, which itself contains some regions, and display them in the Shell. I'm using locally scoped regions to easily handle view injections within my MainView.

Currently I'm searching for a way of communication between the views (viewModels) inside the MainView. Composite events could 开发者_StackOverflow社区do it, but when I publish those events, they are handled in all instances of my MainView, which I really don't want.

Is there a way of raising "locally scoped" composite events like with locally scoped regions? Or may be there's a better way of communicating between views in my case?


It's also possible to create locally scoped EventAggregator and register in a child UnityContainer, created in the MainView (at the same place, where locally scoped region is created).

This is an equivalent to a locally scoped regions imho.


Pass form sender as an argument. (Anyway, there must be a way to distinguish your application's windows - use it.) When you recieve the event, check whether current form ReferenceEquals to sender (Or, check the form 'key').


After much discussion, EventAggregator was selected. Sharing with other in case they are in the same situation and our thought process might help them:

(Problem statement: Refer to my previous comment)

The main View (ViewModel) which has regions to hold views from other modules and which also forms the TabItem view is responsible for cleaning up itself and child views it contains. Hence on TabItem closing event this main View (ViewModel) should inform its child views to gracefully shutdown.

Both EventAggregator and .Net Eventing were thoroughly explored from various aspects as potential candidate for sending the shutdown message.

Since, in a Prism decoupled environment the main View should be technically unaware of its child Views and vice versa, EventAggregator was chosen.

One issue with event aggregator is that it publishes events to whole application, but our requirement was to filter events coming from the tabitemview being closed. The EventAggregator was designed to use a filter to verify if the shutdown request is coming from the same tabitemview (we used scoped regionmanager for every tabItem and this scoped regionmanager was used as the filter) only then it executes the shutdown action. This ensures that triggering shutdown in one tab does not close child views in other tabs which happen to have the same regionname.

Thanks, RDV

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜