tags:

views:

68

answers:

2

Hi,

I am creating an application using WPF which is using Prism framework. I have created Shell form and defined regions in that for Toolbar, Menubar and Workspace. In the workspace area, i am able to load the modules, but I got one requirement where I have to load Employee Master form showing all the employee list in grid. On double click of that employee row in grid it should navigate to the Employee details form. Here I am not supposed to use the Tab control. On double click of the employee grid the Employee Master form should get closed or unloaded and Employee details screen should get loaded.

Any suggestions from Prism Experts on this.

Thanks and Regards, Harry

A: 

I would use an eventaggregator for this or possibly the new VisualStateManager.

One of the traps I fell into with PRISM is overthinking the designs. I eventually stopped using it and ripped it out of my project and things have been going much nicer. Though I still use and love eventaggregator...but theres a big learning curve on the whole regions and viewstate thing...

ecathell
Can you elaborate on this more as I am new to this technolgy... Prism is must in my application
ravi
Tell me WHY Prism is a must. I thought it was a must too until i found out it wasnt...adding it to your project as a newcomer will multiply the complexity and learning curve immensely
ecathell
client requirement is like that
ravi
I have seen your post on "Master Detail across separate views in WPF", can you explain how you handled that using Unity container.Are you using Prism or some other framework there?
ravi
A: 

I find that in these scenarios, people are looking for places to "Prism-ify" their solution. Here's my rule-of-thumb for when to use EventAggregator in Prism:

  1. The application is still useful whether or not a subscriber to the event exists
  2. I cannot use a regular .NET event or other mechanism because the subscriber is defined in another module

Those are the only times I would use EventAggregator to solve a problem. Otherwise, I just use the mechanisms built into WPF. Specifically in a master/detail scenario, the two views are likely useful only together, making them logically the same view, rather than seperate views.

This being the case, I typically do something like this (I've omitted the appopritate DataTemplates in this scenario, but hopefully this is enough to illustrate you don't need anything fancy to solve this problem).

<ListBox ItemsSource="{Binding Turtles}" IsSynchronizedWithCurrentItem="True" />
<ContentControl Source="{Binding Turtles/}" />

This uses a simple WPF mechanism that displays a list of items in a collection and when the user selects an item, the value of "Turtles/" is changed to the item selected. Simple. No need to over-complicate things.

If you really feel like your scenario warrants an EventAggregator (fits with rules #1 and #2 above), then do so as simply as possible... listen to an event both raised by a view model and consume it from a view model (you are using MVVM, right?). Anything more is a headache.

Anderson Imes