0

Prism uses MVVM style convention naming to bind a View to a ViewModel on an Xamarin application.

I recently altered some of the demo code and realized, after spending way too much time debugging, that the pagename didn't match the view.

How can I enable logging, or pre compiler warnings that such a discrepancy exists?

Dan Siegel
  • 5,724
  • 2
  • 14
  • 28
makerofthings7
  • 60,103
  • 53
  • 215
  • 448

2 Answers2

1

Locating the ViewModel for the View is handled in the Prism Core by the ViewModelLocationProvider. You can see here how it is implemented. If you which to override the default behavior and inject your own logging you can use that as a template and call ViewModelLocationProvider. SetDefaultViewTypeToViewModelTypeResolver(YourCustomerLocatorFunctionHere) in your App.OnInitialized.

As for any any precompile warning you'd be on your own there to write a tool.

Dan Siegel
  • 5,724
  • 2
  • 14
  • 28
1

To add to Dan's response, you can bypass the naming convention and register the ViewModel directly with the View by using the Container.RegisterTypeForNavigation<View, ViewModel>() method. This is also faster as reflection will not be used to locate the VM.

  • I will update my projects! Where do I send feedback on Prism? I do love it. Also, my original question(OP) made me wish for a mobile version of this nifty tool: http://nileshviradiya.blogspot.in/2014/11/debugging-routes-aspnet-mvc.html Do you think Prism would support a custom/dynamically built debugging page like that? – makerofthings7 May 04 '17 at 03:18
  • Prism is hosted at https://github.com/prismlibrary/prism. No, Prism will not get that :) –  May 04 '17 at 04:28