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