How to avoid coupling when using regions in Composite WPF

Posted by emddudley on Stack Overflow See other posts from Stack Overflow or by emddudley
Published on 2010-04-29T14:53:37Z Indexed on 2010/04/29 14:57 UTC
Read the original article Hit count: 659

Filed under:
|
|
|

I have an application designed using Microsoft's Composite Application Library. My shell has several regions defined so that I can inject content from separate modules. I'm looking for a design pattern that will reduce the coupling that these regions introduce.

In all examples I have seen, regions are defined and accessed using a string in a static class in the infrastructure project.:

<ItemsControl cal:RegionManager.RegionName="{x:Static inf:RegionNames.TabRegion}">

public static class RegionNames
{
    public const string TabRegion = "TabRegion";
}

This introduces an dependency on the shell from the infrastructure project, because the infrastructure project is now defining some of the shell's capabilities. The CAL RegionManager throws an exception if you attempt to access a region which is not defined, so I must ensure that the infrastructure and shell projects are kept in sync.

Is there a way to isolate the shell's regions so that they are defined only within the shell (no region names in the infrastructure project)?

Is there a way to make regions optional, so that shells can be swapped out even if they don't have all the same regions? (An example: One shell has menu and toolbar regions, another only has the menu... modules should be able to inject into the toolbar if it's available, without failing when it's not)

© Stack Overflow or respective owner

Related posts about composite-wpf

Related posts about regions