My views don't get registerd

Topics: Prism v4 - WPF 4
Aug 3, 2011 at 8:35 PM
Edited Aug 3, 2011 at 8:44 PM

Hi,

I created a WPF app with MEF by following StockTraderRI sample. I have a view "InputView" which is located in ThroughputModule and need to be loaded in "TopRegion" in Shell. This is the code in MEF bootstrapper and I have the imported "AutoPolateExportedViewBehavior.cs", "IViewRegionRegistration.cs", "ViewExportAttribute.cs" in to "Infrastructure" project.

protected override void ConfigureAggregateCatalog()
        {
            base.ConfigureAggregateCatalog();
 
            this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(NYRCPTAGXAddonBootstrapperMEF).Assembly));
            this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(AutoPopulateExportedViewsBehavior).Assembly));
            this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(ThroughputModule).Assembly));
        }
protected override Microsoft.Practices.Prism.Regions.IRegionBehaviorFactory ConfigureDefaultRegionBehaviors()
        {
            var factory = base.ConfigureDefaultRegionBehaviors();
 
            factory.AddIfMissing("AutoPopulateExportedViewsBehavior"typeof(AutoPopulateExportedViewsBehavior));
 
            return factory;
        }
And I put the "[ViewExport]" in the inputView like this:
[PartCreationPolicy(CreationPolicy.NonShared)] // creates a new instance of the view each time it is imported
    [ViewExport(RegionName = "TopRegion")]
    public partial class Inputs : UserControl
    {
        public Inputs()
        {
            InitializeComponent();
        }
    }
This is the region in Shell.xaml:
<ItemsControl Name="TopRegion" regions:RegionManager.RegionName="TopRegion" > </ItemsControl>
 
But when I run the shell is empty, I put break points in AutoPopulateExportedViewBehavior and in the InputView, 
but none of them being hit after bootstrapper.Run(). 
Seems like the view doesn't get registerd at all. I have seen people talked about that the "Infrastructure" assembly was loaded 
through "StockTraderRICommands" which I don't have, but I do have added "AutoPopulateExportedViewsBehavior" added in aggregationCatalog
so it should perform register exported view, right?
What could cause the problem?
Thanks!
Developer
Aug 4, 2011 at 1:40 PM

Hi,

Based on our understanding of the code you've posted, you don't seem to be doing anything wrong when using the ViewExport attribute. Therefore, it would be helpful if you could provide us with a repro sample application, so that we can help you find the cause of your problem.

Thanks,

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

Aug 4, 2011 at 1:48 PM

Hi Guido,

Thank you so much for offering help! I've been stuck for second day on this. My app is actrually a WPF class library hosted in another application (ArcGIS Explore). This app is started when a dockable window is clicked from ArcGIS Explore.

How can I upload my code?

Thanks!

Developer
Aug 4, 2011 at 1:59 PM

Hi,

You could create a simple new application that only has the necessary code to portray the problem you're experiencing, so we can use it to verify what could be making you experience it.

Then you could upload that sample into a page like SkyDrive for us to check it.

Thanks,

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

Aug 4, 2011 at 2:09 PM

I just started so there is really not much code yet

I uploaded the zip (NYRCPTAGXAddon) here:

https://skydrive.live.com/redir.aspx?cid=4f0ce6c357477187&resid=4F0CE6C357477187!121&authkey=jAqYuAXpZr0%24

Thanks!

Aug 4, 2011 at 9:01 PM
Edited Aug 4, 2011 at 9:02 PM

Hi Guido,

Have you had chance to look at the problem with my code?

At mean time, I'm trying out using code through Module initialize to register the view with region (not by ViewExport attribute). So my ModuleA look like this:

 [ModuleExport(typeof(ModuleAIni))]
    public class ModuleAIni : IModule
    {
        [Import]
        public IRegionManager regionManager;
 
        public void Initialize()
        {
            this.regionManager.RegisterViewWithRegion("MainRegion",typeof(ModuleAView));
        }
    }
 
This ModuleA is configured in bootstrapper:
 this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(ModuleAIni).Assembly)); 

 The region is defined in Shell 

<ContentControl prism:RegionManager.RegionName= "MainRegion"  Grid.Row="1" Margin="5,5,5,5" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch"/>

This is basicaly follow the Prism Trainning kit "7-Navigation". But the view currently don't show up, I guess is because the button click is triggering the navigation to get the view. 
What do I need to do if I want the view to show up when app is started?

Thanks!
Aug 5, 2011 at 4:19 AM

These are more tests I did.

Create MEF and Unity standalong WPF app and they both work fine in terms of registering View with region.

Create MEF and Unity WPF hosted in other app (ArcGIS Explore, just like in the code I uploaded), none of them work. When I check the regions using the injected IRegionManager in ModuleA, the count shows 0. Seems like regions can't be identified. Does this make sense?

Thanks!

Aug 5, 2011 at 2:03 PM

Finally, figured out the problem.

Because the Application.current is null if this is a hosted WPF app, I need a dummy class which has to be the subclass of System.Window.Application. One of the test app I create didn't do subclass and it cause others stopped working.

Thanks!

Developer
Aug 5, 2011 at 2:36 PM
Edited Aug 5, 2011 at 3:18 PM

Hi,

I'm glad you've found a solution to your problem. Thank you for sharing this with the rest of the community, as it might be helpful for other users experiencing similar problems when using Prism from within another hosting application.

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