sudarsanyes
sudarsanyes

Reputation: 3204

NavigationService.Navigate throwing exception when called in Prism for UWP

I am using Prism for UWP and I've base classed my App from PrismUnityApplication. I've overridden OnLaunchApplicationAsync and I am trying to call,

NavigationService.Navigate("HighlightsView", null); 

When called, the program throws an exception,

{"The page name HighlightsView does not have an associated type in namespace Panda.UWP.Views\r\nParameter name: pageToken"}

I do have a folder named Views and I do have a view named HighlightsView under the namespace, Panda.UWP.Views.

Is there a naming convention to be followed here? Because if I rename my view from HighlightsView to HighlightsPage, then everything seems to be working just fine!

Upvotes: 0

Views: 657

Answers (2)

Sunteen Wu
Sunteen Wu

Reputation: 10627

Is there a naming convention to be followed here?

The short answer is yes. Prism for the Windows Runtime specifies a ViewModelLocator object, that can be used to manage the instantiation of view models and their associations to views. This approach has the advantage that there’s a single class that’s responsible for view model instantiation.

The ViewModelLocator class uses an attached property, AutoWireViewModel, to associate view models with views once this property is set to True. For more details about the convention please reference Dave's Tech Blog:

  • View models are in the same assembly as the view types.

  • Views are in a .Views child namespace.

  • View names end with “Page”.

  • View models are in a .ViewModels child namespace.

  • View model names correspond with view names and end with “ViewModel”.

The blog also provide how to override Prism’s default conventions you can reference. Brian's blog also describe the similar things about the convention and how to change it.

Upvotes: 2

Taha Azab
Taha Azab

Reputation: 34

simple solution is to rename the HighlightsView.xaml to be HighlightsViewPage.xaml

Upvotes: 0

Related Questions