0

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!

sudarsanyes
  • 3,156
  • 8
  • 42
  • 52

2 Answers2

2

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.

Sunteen Wu
  • 10,509
  • 1
  • 10
  • 21
  • I guess I have all the conventions followed, expect the 3rd one, View names end with “Page”. Like I mentioned in my question, I am trying to reuse most of the classic application code in the UWP version and since wpf prism does not include any constraints related to view ending with "Page", I hit a block. Is there a way I can manually wire views and viewmodels ? – sudarsanyes Aug 09 '17 at 08:22
  • 1
    @sudarsanyes I think yes. Could you please try the " Change those Nasty Conventions" section of Brian's blog? – Sunteen Wu Aug 09 '17 at 08:39
0

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

Taha Azab
  • 34
  • 4