Access other module's controls

Topics: Prism v2 - Silverlight 2, Prism v2 - WPF 3.5
Jun 30, 2009 at 6:03 AM

Hi,

   I want to access controls of the other modules/views so that I can fill them with new data or use the data in the current module/views.

   Example:

   I have a ModuleA with ModuleB. ModuleA has ViewA1, ViewA2, ViewA3 and ModuleB has ViewB1, ViewB2, ViewB3

   I have loaded ModuleA and ModuleB with ViewA1 and ViewB1 in RegionA and RegionB respectively. Both RegionA and Region B are in a Grid split in half.

   Actions

  • On click of a button in ModuleA.ViewA1, I have to load ViewA2 in RegionA. 
  • In ViewA2, on load, I have to access a textbox value in ViewB1. 
  • On click of a button in ViewA2, I have to load ViewB2 in RegionB with a parameter passed from ViewA2.

   We plan not to use Model View Presenter mode to begin with for the POC. But eventually would like to use them.

   Thanks and regards

   Pooran

 

Jun 30, 2009 at 6:19 PM

Hi Pooran,

 

As you know one of the main objectives in Composite Applications is keeping functionality decoupled for testability and maintainability purposes. For this reason, accessing controls placed in views of other modules is not  a recommended practice because you would be breaking the module’s decoupling.

 

I will now try explain how I would personally approach  each of your scenarios separately:

 

On click of a button in ModuleA.ViewA1, I have to load ViewA2 in RegionA

Since the views are in the same module, all you have to do is publish a regular .Net event (or through Event Aggregator, but it is not necessary) to notify whoever is in charge of adding ViewA2 to a region (a ModuleController, a Presenter, etc) that should add it. For this scenario, View Injection is probably the recommended approach.

 

On click of a button in ViewA2, I have to load ViewB2 in RegionB with a parameter passed from ViewA2

In this scenario, since the views are in different modules, you could publish an event with the Event Aggregator (passing the parameter you require as the payload). In the subscriber, which should be in charge of adding ViewB2 to a region, you should add ViewB2 to RegionB (you will already have the parameter).

 

In ViewA2, on load, I have to access a textbox value in ViewB1

My approach here would be having a service shared across the application, which would be kind of the application’s state and store the value of that textbox in the application’s state service. You can read more about a similar situation here.

 

Please let me know if this helps.

 

Damian Schenkelman

http://blogs.southworks.net/dschenkelman

Jul 1, 2009 at 5:13 AM

Hi Damian Schenkelman,
   Thanks a lot for the insights. Will give them a try and get back to you.
   Pooran

Jul 2, 2009 at 4:57 AM

Hi Damian Schenkelman,
    Considered you ideas.. it works.. thanks again :)
    Pooran