Problems with GetView

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

Whats the problem with the method GetView in my App.

thats my View:

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

Thats my module Initialization:

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

        [Import]
        public IRegionManager RegionManager;

        public ModulePosVenda()
        {  }

        public void Initialize()
        {
            var posVendaToolbarView = ServiceLocator.Current.GetInstance<PosVendaToolbar>();
            RegionManager.Regions[RegionNames.MainButtonsRegion].Add(posVendaToolbarView, "PosVendaToolbarView ", false);
            RegionManager.Regions[RegionNames.MainButtonsRegion].Activate(posVendaToolbarView);
        }
    }
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");
                _regionManager.Regions[RegionNames.MainButtonsRegion].Activate(posVendaToolbarView);
            

// Button 2 Click to call Module 2:
                var vendasToolbarView = _regionManager.Regions[RegionNames.MainButtonsRegion].GetView("VendasToolbarView");
                _regionManager.Regions[RegionNames.MainButtonsRegion].Activate(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 4: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 4:15 PM

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

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

        [Import]
        public IRegionManager RegionManager;

        public ModuleVendas()
        {  }

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

 

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 4: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 11:02 AM

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?

 

 

Developer
Dec 10, 2010 at 2: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.

Thanks.

Guido Leandro Maliandi
http://blogs.southworks.net/gmaliandi

Dec 10, 2010 at 3: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.

Thx,

 

Developer
Dec 10, 2010 at 3:50 PM

Luciano,

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

Guido Leandro Maliandi
http://blogs.southworks.net/gmaliandi