Get RegionManager.Regions member in XBAP

Topics: Prism v2 - WPF 3.5
Mar 11, 2009 at 7: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">
    </ItemsControl>
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?

Thanks.
Mar 11, 2009 at 8:20 PM

Hi,

 

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)

            //{

                //base.OnStartup(e);

           

            //}

 

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

            {

                base.OnLoadCompleted(e);

                Bootstrapper bootstrapper = new Bootstrapper();

                bootstrapper.Run();

            }

 

        }

 

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)

        {

            InitializeComponent();

            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

http://blogs.southworks.net/esculli/

Mar 12, 2009 at 1: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 :)

Thanks.