Archive for the 'Composite Application Guidance for WPF' Category

WindowRegionAdapter at CompositeWPF (Prism) Contrib

Finally, I got the time to make the acceptance tests and the documentation for the WindowRegionAdapter!

 

Now, with the help of my workmate Ezequiel Jadib, it is live at CompositeWPF Contrib!

WRAatCompositeWPFContrib

Figure 1. The WindowRegionAdapter in the News section at the CompositeWPF Contrib site.

 

Download

You can get it by downloading the latest change set (you’ll find it in the %ContribFolder%Trunk\Samples\WindowsRegionAdapter folder).

 

Documentation

For more information on the WindowRegionAdapter, you may check the Window Region Adapter article in the Documentation section and my previous post on the WindowRegionAdaptrer: WindowRegionAdapter for CompositeWPF (Prism).

For more information on the latest additions to CompositeWPF Contrib, you may have a look at the following link: CompositeWPF (Prism) Contrib Latest Additions (2008-10-26).

 

Cheers!

Nacho

WindowRegionAdapter for CompositeWPF (Prism)

With the help of my dear workmate Julian Dominguez, I’ve been developing a new region adapter: the WindowRegionAdapter. It provides a way to show views in separate windows and has the following features to take into account:

  • It uses a SingleActiveRegion, so that only one (or no) view (one window) is active at a time.
  • It provides a WindowStyle property (of type Style) which allows the developer to specify a custom style to use as a template for all the windows shown in the region.

How to use the WindowRegionAdapter

Step 1 – Register the adapter mapping

The first thing you will need to do is to register the mapping for the Region Adapter for the type Window. To accomplish this, you must override the ConfigureRegionAdapterMappings() method of the Bootstrapper, retrieving the RegionAdapterMappings from the container, and calling its RegisterMapping() method, sending the Window type and a new instance of the WindowRegionAdapter, as follows:

protected override RegionAdapterMappings ConfigureRegionAdapterMappings()
{
    RegionAdapterMappings regionAdapterMappings = Container.TryResolve<RegionAdapterMappings>();

    if (regionAdapterMappings != null)
    {
        regionAdapterMappings.RegisterMapping(typeof(Window), new WindowRegionAdapter());
    }

    return base.ConfigureRegionAdapterMappings();
}

[Recommended]: Alternatively, you may provide a custom style to use as template for all the windows shown in the region by setting its WindowStyle property on initialization (as shown in the sample application):

regionAdapterMappings.RegisterMapping(typeof(Window), new WindowRegionAdapter() { WindowStyle = (Style)Application.Current.FindResource(“WindowTemplate”) });

 

Step 2 – Set the owner for the child windows

To use the WindowRegionAdapter, you must add the cal:RegionManager.RegionName attribute to a Window (for example, the Shell window), as follows:

<Window x:Class=”Example.Shell”
xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation”
xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml”
xmlns:cal=”http://www.codeplex.com/CompositeWPF”
Title=”MainWindow” Height=”400″ Width=”500″ WindowStartupLocation=”CenterScreen” cal:RegionManager.RegionName=”MyWindowRegion”>

The WindowRegionAdapter will get this window and will use it to set the value of the Owner property of each child window to this window.

 

Screenshots

WRAViewDesign

Figure 1. View at design time.

 

WRAViewRun

Figure 2. View displayed in a new window (by the Window Region Adapter) at run time.

 

WRAExampleRunning

Figure 3. The sample application running with several views displayed.

 

Disclaimer

This code is provided “AS IS” with no warranties. You can use it freely. It includes the binaries of Composite Application Library and Unity Application Block.

 

Download the WRAExample sample application here!

 

EDITED 10/26/2008: Now, it’s available at CompositeWPF Contrib! Get the latest change set here!

 

Enjoy! :D

As always, any feedback is welcome! :)

 

Related posts:

Cheers!

Nacho