• Home
  • Blog
  • Video
  • About
Prism

Prism – ViewModelLocator Custom Registrations

January 22, 2019Posted by Brian Lagunasin Prism, UWP, Video, WPF, Xamarin

There may be instances where your app is following the ViewModelLocator default naming convention, but you have a number of ViewModels that do not follow the convention. Instead of trying to customize the naming convention logic to conditionally meet all your naming requirments, you can register a mapping for a ViewModel to a specific view directly with the ViewModelLocator by using the ViewModelLocationProvider.Register method.

The following examples show the various ways to create a mapping between a view called MainWindow and a ViewModel named CustomViewModel.

//Type / Type
ViewModelLocationProvider.Register(typeof(MainWindow).ToString(), typeof(CustomViewModel));

//Type / Factory
ViewModelLocationProvider.Register(typeof(MainWindow).ToString(), () => Container.Resolve<CustomViewModel>());

//Generic Factory
ViewModelLocationProvider.Register<MainWindow>(() => Container.Resolve<CustomViewModel>());

//Generic Type
ViewModelLocationProvider.Register<MainWindow, CustomViewModel>();

Please visit this video sponsor
https://bit.ly/prism-infragistics

Help support Prism and become a Patron
https://www.patreon.com/prismlibrary

Tags: Prism, ViewModelLocator
Share in social networks

Click here to cancel reply.

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Search

3,983 followers -1 followers Subscribe To RSS

Categories

  • Code Camps
  • Events
  • HoloLens
  • Infragistics
  • Misc
  • Prism
  • Silverlight
  • User Groups
  • UWP
  • Video
  • Windows 8
  • WPF
  • Xamarin

Site Map

  • Desktop to Web Series YouTube Official Contest Rules
  • Home
  • Blog
  • Video
  • About

©2015 Brian Lagunas' XAML Blog

  • Home
  • Blog
  • About