tags:

views:

237

answers:

2

Hi,

I've got an little tool similar to the Windows Control Panel. The tool allows us to manage users, configure databases, manage scripts, etc. The home page presents all the sub categories of the application. When you click on a link, it loads the view of this category in the right panel and a small left panel shows the tasks available for this category. Simple.

Basically, what I want to do is to have a "contextalized" status bar. If you are in a view where you need to be connected, the status bar should show you state. If you are in a view where informations should be displayed, I want it in my status bar.

I already put a Region (named StatusBarRegion for the status bar in my shell. For each module, I registered the StatusBarView of this module on the shell's region.

Now, I want to handle the change of context. I need to activate the good view when it's time.

But everytime I try to resolve the StatusBarRegion, it can't be found in the regions of the region manager.

See,

var region = _regionManager.Regions[.RegionNames.StatusBarRegion];
region.Activate(_container.Resolve<StatusBarView>());

The region is always null. Why's that ?

Thanks for your time.

A: 

The reason why the region was null ? The piece of code was in the Initialize method of the Module, so the UI was not created yet.

For the best way to manage my status bars, I'm still wondering how I'm going to do it.

esylvestre
+1  A: 

Double check RegionNames.StatusBarRegion value if already same with region target in your shell.

If it does, region shouldn't be null I think, except you put your handle in your view/viewmodel of module and you hadn't get region manager and container on constructor.

Let say it handled in your view SilverlightUserControl1. The constructor could be like this:

private readonly IRegionManager _regionManager;
private readonly IUnityContainer _container;

public SilverlightUserControl1(IRegionManager regionManager, IUnityContainer container)
{
    _regionManager = regionManager;
    _container = container;
}

private Button1_Click(object sender, RoutedEventArgs e)
{
    var statusBarView = _container.Resolve<StatusBarView>();
    statusBarRegion = _regionManager.Regions["StatusBarRegion"];

    statusBarRegion.Add(statusBarView, "StatusBarView");
    statusBarRegion.Activate(statusBarView);

    // or you could remove all views in `ActiveViews` and add the view then
    // (no need to activate)
}
Jeaffrey Gilbert
Thank you for your time, it's been appreciated.But like I said previously, the region is null because the code was in the Initialize method of the Module, so the UI was not created yet, so the region could not be resolved.This said, your answer gives a good example of the proper manner to use regions. Thanks again.
esylvestre