Window Region Adapter

The WindowRegionAdapter provides a way to show views in separate windows with a custom style:

Important Features

  • 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

  • 1 - Register the adapter mapping for the Region Adapter for the type Window:
protected override RegionAdapterMappings ConfigureRegionAdapterMappings() 
{ 
    RegionAdapterMappings regionAdapterMappings = Container.TryResolve<RegionAdapterMappings>();
    if (regionAdapterMappings != null) 
    { 
        regionAdapterMappings.RegisterMapping(typeof(Window), new WindowRegionAdapter()); 
    }
    return base.ConfigureRegionAdapterMappings(); 
}

Recommended: Provide a custom style to use as template for all the windows shown in the region by setting its WindowStyle property on initialization:
regionAdapterMappings.RegisterMapping(typeof(Window), new WindowRegionAdapter() { WindowStyle = (Style 
Application.Current.FindResource("WindowTemplate") });
  • 2 - Add the cal:RegionManager.RegionName attribute to a Window (for example, the Shell window) to set the owner for the child windows, 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">
  • 3 - Display a view as follows:
MyViewPresenter myViewPresenter = myContainer.Resolve<MyViewPresenter>();
_regionManager.Regions["MyWindowRegion"].Add(myViewPresenter.View);

More Information

For more information and a sample application, you may visit WindowRegionAdapter for CompositeWPF (Prism).

Last edited Oct 26, 2008 at 5:44 PM by ejadib, version 2

Comments

No comments yet.