how to pass a variable between two modules

Topics: Prism v2 - WPF 3.5
Mar 27, 2010 at 2:00 AM


What I'm trying to do is pass a variable from one module to another module.  I know I could use the EventAggregator, but it seems a bit messy for this situation:

I have a tree in one module (moduleTree) and a RibbonBar in another module (moduleRibbonBar).  When I click on the node of a tree it gets the ID of that node. In the RibbonBarModule When I click on a button "LoadMappings", it should get the Mappings for that ID and load them.

So here are the steps that I want to happen:

1) Click on Node in moduleTree to get ID

2) Click on button in moduleRibbonBar to load the mappings

3) Get the ID of the selected node from moduleTree from moduleRibbonBar

4) Load up the settings.

The problem with using the Event Aggregator is that I would need 2 event calls:

  • "LoadMappings" Button is clicked in moduleRibbonBar, throws an event
  • ModuleTree catches the event and gets the ID of the selected node, throws an event
  • Module RibbonBar catches the event that Module Tree throws, and now it can do its thing.

So is this the way I'm supposed to do it?  I've tried to mess around with registering Types:

<font size="2">



ISelectedTest, Services.SelectedTest>(new ContainerControlledLifetimeManager());

But I doubt that is the way to go.  Can anyone help me out on this one?



Mar 29, 2010 at 1:24 AM

I don't think you need 2 events. What about if the moduleTree fires an event when it is selected and moduleRibbonBar stores the id of the selected node? then, if button on the modlrRibbonbar is clicked it can load the mappings from the stored id.

Anothee possibility is to have the ribbonbar raise an event (and keep a reference to the event parameter) and have the moduleTree set an id property on the parameter. Not done this and it could get a bit messy finding when the property was set.



Mar 29, 2010 at 4:53 AM

geez I feel pretty stupid...

Yeah making an event fire when the tree node gets clicked, and having the ribbon bar listen for that event will work just fine.

Thanks Mark.