Get RegionManager.Regions member in XBAP

Topics: Prism v2 - WPF 3.5
Mar 11, 2009 at 6:53 AM
Hi All,

i'm creating an XBAP application using PRISM and i find a problem when we want to get the member of RegionManager.Regions an error occured. but this only happen in XBAP. while in WPF, same codes, it works fine.
Below are some of my codes:
I set a region name in Shell.xaml:
    <ItemsControl Name="MainRegion" cal:RegionManager.RegionName="MainRegion">
and when i try to execute this code in a module:
IRegion region = regionManager.Regions["MainRegion"]; --> an error occured, the system can't find the region name = "MainRegion" (the region list is empty).

i try to execute other sample projects (in WPF), there were no error. they work fine.

Or may be i missed something. can someone help me to explain this?

Mar 11, 2009 at 7:20 PM



We have followed the steps in the HelloWorld for WPF Hands on Lab, with some adjustments, to create the HelloWorld as a XBap (WPF Browser Application) in a fashionable manner. The following were the changes made (apart from Windows being Pages, of course):

1.       In the App.xaml file define add the attribute StartupUri="Shell.xaml".

2.       Remove or comment this code from the XAML file: cal:RegionManager.RegionName="MainRegion".

3.       In the CreateShell method of the Bootstrapper class replace the existing code for the following one:


      Window window = App.Current.MainWindow;


            Shell shell = window.Content as Shell;

            RegionManager.SetRegionName(shell.MainRegion, "MainRegion");


            return shell;


4.       Update the code behind class of the App.xaml file with this one:

               public partial class App : Application



                        // You don't need to override this method

            //protected override void OnStartup(StartupEventArgs e)






            protected override void OnLoadCompleted(System.Windows.Navigation.NavigationEventArgs e)



                Bootstrapper bootstrapper = new Bootstrapper();






After running the application to check if the previous steps worked correctly, the codebehind of the HelloWorldView was modified to this:

// Pre existing namespaces go here…

using Microsoft.Practices.Composite.Regions; // Added this namespace


namespace HelloWorldModule.Views


    /// <summary>

    /// Interaction logic for HelloWorldView.xaml

    /// </summary>

    public partial class HelloWorldView : UserControl


        IRegionManager manager;


        public HelloWorldView(IRegionManager regionManager)



            manager = regionManager;



private void Button_Click(object sender, RoutedEventArgs e)


            IRegion region = manager.Regions["MainRegion"];//This line returns the expected region.

            Application.Current.MainWindow.Title = region.Name; //The correct text is shown.





You might find reading the following thread useful, even though it is not directly related to your situation, deals with an issue with regions:

·         Activate a different view in a XBAP application


You should also take into account that since XBAPs are not in the scope of the Composite Application Guidance for WPF & SL, some particular things might need to be done differently.

Could you provide more information on your scenario? Are you performing any particular operation before trying to get the regions? Are there any permission issues that you have faced/might be facing?


Ezequiel Sculli

Mar 12, 2009 at 12:57 AM
Hi Ezequiel,

Thanks for the feedback. I have followed your instructions and now it's working well. thanks.
there weren't any particular operations and i haven't found any permission issues yet.
thanks for your help :)