IRegionManager and Injection using MVVM

Topics: Prism v2 - Silverlight 2
Feb 24, 2009 at 6:00 PM
How would I use Dependency Injection using the MVVM pattern? Is this possible?

Feb 24, 2009 at 7:46 PM
Yes,  the following blog shows example w/source and short Webcast 
Feb 24, 2009 at 8:39 PM
Thanks you for the information and pointing me in the right direction. One issue I can't figure out is how I would remove a view. I have a login control that loads into the main region. After I click login I want login control view to be removed and then replaced with another view. Do you have any suggestions? Thanks  
Feb 24, 2009 at 8:43 PM
Perhaps the following may help you?

Feb 24, 2009 at 10:27 PM
Does this solution work for Silverlight or just WPF? I'm getting fatal errors when trying implement. Invalid attribute value {Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}} for property Click.CommandParameter. [Line: 78 Position: 56]
Feb 25, 2009 at 3:04 AM

Sorry, that was in the context of WPF.

I haven't had to remove a view from Silverlight (yet).  Curious as to how it was done I went to the docs and searched for "Removing"

I believe your answer will lie under the following topic - I provided and excerpt for your convenience.

How to: Show a View in a Region Using View Injection UI Composition

In some cases, you may want to add a view to a region and associate a name to it. By associating a name to a view, you can retrieve the view later from the region to perform actions with it, such as removing the view from the region, showing it, or editing it. Views that have an associated name are referred to as named views.

To add a named view to a region

  • Invoke the method Add on the region, passing as parameters the view instance and the view name, as shown in the following code.
    C# Copy Code
    mainRegion.Add(new View(), "View 1");

To retrieve the view instance by its name

  • Invoke the GetView method on the region, passing the view's name as the parameter, as shown in the following code.
    C# Copy Code
    View view = mainRegion.GetView("View 1") as View;


Feb 25, 2009 at 1:45 PM
Yes, that works, thank you.  Am I approaching this right, by removing the view, or is there another way you would recommemd? I also noticed in the Prism RI project in the OrdersController they use a command proxy to unregister commands. Should you unregister commands anytime you remove a view?  
Feb 25, 2009 at 3:17 PM
I let ASP.NET handle authentication - I configure the Web.Config to launch my login form (Forms Authentication) and use the existing ASP.NET security infrastructure; Silverlight isn't a player.