Cannot navigate to xaml in different project

Topics: Prism v4 - Silverlight 4
Nov 11, 2010 at 7:37 PM

I have the following project structure:

FactoryMillPlanning

Bootstrapper

FactoryMillPlanning.Navigation

Views/NavigationView.xaml

NavigationModule.cs

FactoryMillPlanning.Requirements

Views/RequirementSearch.xaml

RequirementSearchModule.cs

  

From inside the NavigationView.xaml.cs file I'm trying to navigate to the RequirementSearch.xaml file but it's not working.  I've tried the following:

private static Uri reqSearchViewUri = new Uri("/FactoryMillPlanning.Requirements;component/Views/RequirementSearch.xaml", UriKind.Relative);

 

private void TreeViewItem_Selected(object sender, RoutedEventArgs e)

{

 this.regionManager.RequestNavigate("MainContentRegion", reqSearchViewUri);

 

 

 

}

 

Here's the stack trace I get from RequestNavigate:

Cannot create navigation target 'FactoryMillPlanning.Requirements;component/Views/RequirementSearch.xaml'.

Activation error occured while trying to get instance of type Object, key "FactoryMillPlanning.Requirements;component/Views/RequirementSearch.xaml"

Am I missing something.  I'm rather new to SilverLight and PRISM.following.  I'm using Drop 10.

Thanks

Scott

Nov 11, 2010 at 8:22 PM
Edited Nov 11, 2010 at 8:23 PM

Hi Scott,

Nice to see that started using Prism. Navigation in Prism requires you to export views if you are using MEF or register views if you are using Unity. It means that the container must contains the views, so in the navigation pipeline, views can be create/locate to display this in a region.

That said, have you exported/registered views in the container?

Please take into account that if you are using Unity, it is necessary to indicate TFrom type in the RegisterType<TFrom, TTo> method.  If your view does not implement any interface for mapping, you could use Object. So you registration code might be similar to the following (pseudo-code):

_container.RegisterType<Object, RequirementSearch>()

For more information about this, you could take a look at the following forum thread: LoadModule problem when OnDemand, please see my last post in the thread. 

If you need more guidance about Navigation, you could also take a look at the Navigation Quickstart.

Additionally, you can find the following posts in the Karl Shifflett Blog interesting:

If you continue experiencing this situation, could you please share a repro sample?

Hope this helps.

Fernando Antivero 
http://blogs.southworks.net/fantivero

Nov 11, 2010 at 9:00 PM

Hi Fernando,

Thanks for the quick reply.  I'm using MEF to export my views.  All of my views can be navigated to except for one.  The views that are working are in the same project that calls the RequestNavigate method.   The uri for these is simple since it's in the same project:

private static uri introductionViewUri = new uri("/Introduction", urikind.Relative);

The view I'm having trouble with is outside the project that calls the RequestNavigate method.  I was thinking it was my uri that was the problem.  To make sure I moved the problem view and it's module into the same project so I'd have a simple uri and it worked.  The uri that is giving me trouble is shown below.

private static uri reqsearchviewuri = new uri("/FactoryMillPlanning.Requirements;component/Views/RequirementSearch", urikind.Relative);

Does this look correct?  I can send you the code, should I email it?

 

Thanks

Scott

 

Nov 15, 2010 at 7:12 AM

Hi Scott,

Did you figure out the solution? I'm having the same issue. I have a view in another silverlight application. And when I try to do _regionManager.RequestNavigate("Region1", new Uri("MainPage", UriKind.Relative) it doesnt work.

My MainPage in the other silverlight projects is decorated with the Export attribute with "MainPage" as the contract name.

Plus I guess in this scenario we dont need modulecatalog at all if the RequestNavigate can handle the navigation for us right?

Nov 15, 2010 at 2:29 PM

Hi,

No I wasn't able to get it to work. I decided to use a delegatecommand instead. I'm pretty new to prism and silverlight but I think the modulecatalog is for modularity and is not related to navigation. The modulecatalog handles the loading and initialization of modules.

Thanks

Scott

 

Nov 15, 2010 at 2:40 PM
Thanks scott.

I understand modularity is different. But whether its modularity or navigation its ultimately loading a xap/usercontrol into a region. I believe that's what the requestnavvigate should do.


From: mcmics <notifications@codeplex.com>
To: Shivshankar, Ganesh (IT/IN)
Sent: Mon Nov 15 19:59:11 2010
Subject: Re: Cannot navigate to xaml in different project [CompositeWPF:234351]

From: mcmics

Hi,

No I wasn't able to get it to work. I decided to use a delegatecommand instead. I'm pretty new to prism and silverlight but I think the modulecatalog is for modularity and is not related to navigation. The modulecatalog handles the loading and initialization of modules.

Thanks

Scott

Read the full discussion online.

To add a post to this discussion, reply to this email (CompositeWPF@discussions.codeplex.com)

To start a new discussion for this project, email CompositeWPF@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on CodePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at CodePlex.com

This e-mail (including any attachments) is confidential, may contain
proprietary or privileged information and is intended for the named
recipient(s) only. Unintended recipients are prohibited from taking
action on the basis of information in this e-mail and must delete all
copies. Nomura will not accept responsibility or liability for the
accuracy or completeness of, or the presence of any virus or disabling
code in, this e-mail. If verification is sought please request a hard
copy. Any reference to the terms of executed transactions should be
treated as preliminary only and subject to formal written confirmation
by Nomura. Nomura reserves the right to monitor e-mail communications
through its networks (in accordance with applicable laws). No
confidentiality or privilege is waived or lost by Nomura by any
mistransmission of this e-mail. Any reference to "Nomura" is a
reference to any entity in the Nomura Holdings, Inc. group.
Please read our Electronic Communications Legal Notice which forms
part of this e-mail: http://www.Nomura.com/email_disclaimer.htm
Nov 16, 2010 at 4:34 AM

Hi Scott,

I found a way to do this. Well it doesnt get rid of the ModuleCatalog. The mistake I was making was to asking the regionmanager to load a exported view into a region even before the export was done. So assume I have a project with the following structure

  • Web
    • MainHost
      • Shell.xaml : this has a ContentControl marked with RegionName "Region1"
    • ModuleA
      • ModuleAView.xaml : this is marked with a Export "ModuleAView"
      • Module : this implements IModule with the ModuleExport attribute on it. I have kept the Initialize method empty as it does nothing at the moment

Now I need to download the ModuleAView in ModuleA into Region1. All I need to do is this

private void LoadModule()
        {
            _moduleManager.LoadModuleCompleted += _moduleManager_LoadModuleCompleted;
            var moduleInCatalog = _moduleCatalog.Modules.Single(m => m.ModuleName.ToLower() == "ModuleA");
            if (moduleInCatalog.State == ModuleState.NotStarted || moduleInCatalog.State != ModuleState.Initialized)
                _moduleManager.LoadModule(moduleInCatalog.ModuleName);

            
        }

void _moduleManager_LoadModuleCompleted(object sender, LoadModuleCompletedEventArgs e)
        {
            var regionManager = Container.GetExportedValue();
            var query = new UriQuery();
            query.Add("text", "Some query");
            regionManager.RequestNavigate("Region1", new Uri("ModuleAView" + query, UriKind.Relative), NavigationCompleted);
        }

Doing the above does the job. So in effect the ModuleA really need not worry about which region it needs to place the ModuleAView. It can be completely decoupled from a region. Plus you can now take advantage of the INavigationAware for passing parameters to modules instead of event aggregators.

Nov 16, 2010 at 2:17 PM

Hi - Thanks for the info.