Load module in shell in WPF Browser Application

Jul 17, 2008 at 5:57 AM


I am creating xbap application with Composite Application. it contains four modules and
one WPF browser application. this application contain two pages one is login.xaml and shell.xaml.

once i logged in, it should open all modules in shell page.

here only i am getting problem to show module in shell becasue, shell.xaml is the Page. not Window.

if it is Window, we will give following code to show the modules in shell .

shell shell = Container.Resolve<shell>();
return shell;

but i am using Page not Window. so how do show modules in shell.
when i am using Page, shell.show() method not working. it is raising error.

please help me as soon as possible to fix this issue.


Jul 18, 2008 at 2:28 AM
I haven't tried to create and Xbap application with C/WPF yet, though there shouldn't be any reason why you can't use the CreateShell() method. What you do with the shell creation is up to you, you don't need to invoke shell.Show(), you can even return null but if you do this you must register the region manager to your UI manually.

Jul 18, 2008 at 2:31 AM

The following works - please let me know if you find a better way.

I used the Commanding.sln and added a WpfBrowserApp project - the CommandingBootStrapper.cs file follows:

using System.ComponentModel;
using System.Windows;
using Commanding.Modules.Order;
using Microsoft.Practices.Composite.Modularity;
using Microsoft.Practices.Composite.UnityExtensions;
using WpfBrowserApp;

namespace Commanding
    class CommandingBootstrapper : UnityBootstrapper
        Page1 shell = null;
        public CommandingBootstrapper(Page1 page)
            shell = page;

        protected override DependencyObject CreateShell()
            return shell;

        protected override IModuleEnumerator GetModuleEnumerator()
            return new StaticModuleEnumerator().AddModule(typeof(OrderModule));

Page1 Code behind looks as follows (didn't need the Container - just wanted to see if it would be there - it was :)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.Practices.Unity;
using Commanding;

namespace WpfBrowserApp
    /// <summary>
    /// Interaction logic for Page1.xaml
    /// </summary>
    public partial class Page1 : Page
        private IUnityContainer _container;
        public IUnityContainer Container
            set { _container = value; }

        public Page1()

            CommandingBootstrapper bootstrapper =
                new CommandingBootstrapper(this);


I grabbed the XAML from Command projects Shell (minus the Window.Background elements) so that the CommandingBootStrapper wouldn't puke - it needs the GlobalCommandsRegion and MainRegion.   I was pretty surprised to find the Page1 XBAP code ran exactly as the Shell WPF! 

<Page x:Class="WpfBrowserApp.Page1"
            <RowDefinition Height="50"/>
            <RowDefinition Height="30"/>
            <RowDefinition Height="*"/>
        <StackPanel Grid.Row="1"  Margin="10,0,10,0">
            <ItemsControl cal:RegionManager.RegionName="GlobalCommandsRegion" />
        <Border Grid.Row="2" CornerRadius="4,4,4,4" BorderBrush="#193441" Background="#FCFFF5" BorderThickness="2,2,2,2" Margin="10,0,10,10" Padding="5">
                <ItemsControl cal:RegionManager.RegionName="MainRegion" />
        <Label HorizontalAlignment="Left" Margin="155,5,0,0" Width="Auto" Content="QuickStart" FontWeight="Normal" Foreground="#FF373737" FontSize="24" FontFamily="Corbel"/>
        <Label HorizontalAlignment="Left" Margin="10,5,0,0" Width="Auto" Content="Commanding" FontWeight="Bold" Foreground="#FF373737" FontSize="24" FontFamily="Corbel"/>
        <Separator Margin="0,0,0,0" VerticalAlignment="Bottom" Height="10" BorderBrush="#193441"/>
Apr 23, 2009 at 12:45 PM
hi BillyKat

your work around is great but it kept erroring for me. The region manger was trying to add regions before the UnityContainer was set, because they where declared in the XAML. i had to change a couple of things.

would fail in RegionManager.cs line 121

IServiceLocator locator = ServiceLocator.Current;

ServiceLocator.Current null reference error.

So i made a couple of changes

<ItemsControl Name="GlobalCommandsRegion" />
<ItemsControl Name="MainRegion"  />


protected override DependencyObject CreateShell()

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