Making region on non-ContentControl or ItemsControl based UI element results in weird behaviour

Topics: Prism v2 - WPF 3.5
Feb 22, 2009 at 10:23 PM
Hi,

I just started playing with the CompositeWPF library, and so far it seems really powerfull. However I got this issue while trying to fast without RFTM'ing ;)

I created a new Shell project, just like described in the help file, with a ShellWindow and Bootstrapper. However I defined my Shell with the following XAML:

    1 <Window x:Class="Shell.ShellWindow"

    2         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    3         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    4         xmlns:cal="http://www.codeplex.com/CompositeWPF">

    5 

    6     <DockPanel cal:RegionManager.RegionName="Main">

    7         <Grid></Grid>

    8     </DockPanel>

    9 

   10 </Window>

<!--EndFragment-->
If you now run the application, it compiles perfectly however, on startup vshost.exe crashes, with an internal error as follows:

DEBUG: Configuring container. Priority: Low. Timestamp:2009-02-23 00:20:29Z.
DEBUG: Configuring region adapters. Priority: Low. Timestamp:2009-02-23 00:20:29Z.
DEBUG: Creating shell. Priority: Low. Timestamp:2009-02-23 00:20:30Z.
A first chance exception of type 'System.Collections.Generic.KeyNotFoundException' occurred in Microsoft.Practices.Composite.Presentation.dll
A first chance exception of type 'Microsoft.Practices.Composite.Presentation.Regions.Behaviors.RegionCreationException' occurred in Microsoft.Practices.Composite.Presentation.dll

It took me a while to figure the following out:

To create a region, you need to add the RegionManager.RegionName property in XAML to a ContentControl-based UI element or an ItemsControl-based UI element that has built-in support in the Composite Application Library.

Maybe this behaviour is intentional but I think it's more friendly to throw an exception telling me I'm trying to doing something stupid :)