Magellan and Composite WPF

Back to: Magellan Home

Magellan was designed to work with Composite WPF from day one. Composite WPF provides support for multiple modules, loosely coupled pub/sub eventing, and regions for sub-dividing zones in the UI. However, Composite WPF does not enforce any particular UI pattern - MVVM, MVP and MVC could all work.

Magellan and Composite WPF can work well together to create a composite navigation-oriented application using the MVC pattern. Here are some examples:

  • Composite WPF modules could contain views and controllers
  • Composite WPF events could be used for navigation - i.e., a Navigate event that could be raised by different modules and services
  • Instead of pages, Magellan view results could return UserControls that are added to regions

Region Support

For region support, Magellan.Composite.dll contains some extensions that can be used. A controller may look like this:

public class ShellController : CompositeController 
{
    public ActionResult Explorer()
    {
        return CompositeView("Explorer").InRegion("LeftRegion");
    }
}

On application startup, the view can be navigated to via:

Navigator.Primary.Navigate("Shell", "Explorer");

Lastly, an additional Region View Engine needs to be registered. As discussed in the IOC topic, you can also use a custom view activator to control how views are instantiated, if you want to use IOC. In this case we'll use the Microsoft common ServiceLocator:

ViewEngines.Engines.Clear();
ViewEngines.Engines.Add(new PageViewEngine(new ServiceLocatorViewActivator()));
ViewEngines.Engines.Add(new WindowViewEngine(new ServiceLocatorViewActivator()));
ViewEngines.Engines.Add(new CompositeViewEngine(new ServiceLocatorViewActivator()));

When the InRegion extension method is used, and the view class derives from UIElement, the region view engine will use the service locator to resolve the default RegionManager, and then add the view to the region.

Controller Factory

There is also a new controller factory that can be used with the Common Service Locator. It will automatically back onto ServiceLocator.Current to resolve controllers, so you just have to register them in the container:

ControllerBuilder.Current.SetControllerFactory(new ServiceLocatorControllerFactory());

See also:

Back to: Magellan Home

Last revised: 30 Dec, 2009 04:29 AM History

Discussion

Yannick
Yannick
01 Mar, 2010 10:21 PM

Hi Paul,

First, great thanks for your hard work. WPF applications are easier to develop with Magellan.

I have a question about composition with CompositeWPF.

I want activate several views in same time inside an action. Is it possible, and if it's the case, how ?

Your Comments

Used for your gravatar. Will not be public.

Posting code? Indent it by four spaces to make it look nice. Learn more about Markdown.

Preview