Problems with GetView

Dec 7, 2010 at 2:18 PM
Edited Dec 7, 2010 at 2:19 PM
Hi Guys,

Whats the problem with the method GetView in my App.

thats my View:

    [RegionMemberLifetime(KeepAlive = true)]
    public partial class PosVendaToolbar : UserControl
    { ... }

Thats my module Initialization:

        InitializationMode = InitializationMode.OnDemand,
        DependsOnModuleNames = new[] { "ModuleShared" })]
    public class ModulePosVenda : IModule

        public IRegionManager RegionManager;

        public ModulePosVenda()
        {  }

        public void Initialize()
            var posVendaToolbarView = ServiceLocator.Current.GetInstance<PosVendaToolbar>();
            RegionManager.Regions[RegionNames.MainButtonsRegion].Add(posVendaToolbarView, "PosVendaToolbarView ", false);
I have another module with the same configuration.
At my shell, i have 2 buttons, to change the modules,
// Button 1 Click to call Module 1:
                var posVendaToolbarView = _regionManager.Regions[RegionNames.MainButtonsRegion].GetView("PosVendaToolbarView");

// Button 2 Click to call Module 2:
                var vendasToolbarView = _regionManager.Regions[RegionNames.MainButtonsRegion].GetView("VendasToolbarView");

if i hit button 1, its ok.. its load the view in the region, if i hit button 2, its ok.. its load the view in the region, but if i hit back the button 1, the GetView method return null, so i canto load the view again.
the RegionManager.Region[xxx].Views have 2 view (thats corret).
What am i doing wrong?
Dec 7, 2010 at 5:02 PM

When do you load VendasToolbarView into the regionmanager?  I am assuming that these are also 2 completely different modules?

Dec 7, 2010 at 5:15 PM

i just didnt post the other module that loads the vendatoolbar (its a big post), but its the same as PosVendaModule:

        InitializationMode = InitializationMode.OnDemand,
        DependsOnModuleNames = new[] { "ModuleShared" })]
    public class ModuleVendas : IModule

        public IRegionManager RegionManager;

        public ModuleVendas()
        {  }

        public void Initialize()
            var vendasToolbarView = ServiceLocator.Current.GetInstance<VendasToolbar>();
            RegionManager.Regions[RegionNames.MainButtonsRegion].Add(vendasToolbarView, "VendasToolbarView ", false);


The main problem here is, my region.Views, have 2 views, but i cant find them with the Method GetView. I Am doing something wrong?

Dec 8, 2010 at 5:52 AM

I don't see any error in code other than it could be the second Toolbar View is getting GC'd, not totally sure.

Dec 8, 2010 at 12:02 PM

How can i solve that problem?

The ReiongManager.Region[xxx].Views, have exactaly 2 Views, But i cant get then passing the viewName (GetView("ViewName")), the the view is in the region, if i use the method ,FirstOrDefault() or LastOrDefault() i can get the 2 view in the region.

this is the best way to Get the View with a Name? is there another way to do that?



Dec 10, 2010 at 3:13 PM

Hi Luciano,

The way you're obtaining your views is valid, but that's not the expected way to get a view if you wish to be aware of its name.

From the code that you've posted, it doesn't look like you've done something wrong. If you continue experiencing issues with the GetView method, it could be useful if you could provide a Repro sample, so that we can help you further with this scenario.


Guido Leandro Maliandi

Dec 10, 2010 at 4:44 PM

the problem is that your sample its little big, and have acess to some Data Serice Via wcf. i dont think i can provide a Repro Sample.

But i Changed the GetView with RegionManager.RequestNavigate(...), and its working now.



Dec 10, 2010 at 4:50 PM


Thank you for sharing your findings with the rest of the community, as other users might be interested in similar scenarios.

Guido Leandro Maliandi