Skip to content

v2.0-preview5

Compare
Choose a tag to compare
@mysteryx93 mysteryx93 released this 02 Mar 19:37
· 43 commits to master since this release

V2.0-preview5 is ready!

What's new: StrongViewLocator to register ViewModel-View combinations in a strongly-typed way to avoid the use of reflection. Useful if you want to use Assembly Trimming! Works for both desktop and mobile and selects the View accordingly.

Sample ViewLocator registration:

locator = new StrongViewLocator() { ForceSinglePageNavigation = false }
    .Register<MainViewModel, MainView, MainWindow>()
    .Register<CurrentTimeViewModel, CurrentTimeView, CurrentTimeWindow>()
    .Register<ConfirmCloseViewModel, ConfirmCloseView, ConfirmCloseWindow>();

build.RegisterLazySingleton(() => (IDialogService)new DialogService(
    new DialogManager(viewLocator: locator),
    viewModelFactory: x => Locator.Current.GetService(x)));

It could be done even better. This StaticViewLocatorGenerator (usage here) could be adapted to be more generic and serve for our needs. It would use a Source Generator to generate ViewModel-View mapping at compile-time using naming standards and removing the need for reflection. If someone has experience with Source Generators, contribution is welcomed!