ViewModels in ViewModelLocator MVVM Light

First, lets look at what ViewModelLocator does and why we use it: ViewModelLocator is declared as an object on our App.xaml page and is an application singleton. We’re going to have one, and only one of them available to the application when it runs. ViewModelLocator is the source for all our ViewModels in MVVM Light. … Read more

how to use MVVMLight SimpleIoc? [closed]

SimpleIoc crib sheet: 1) You register all your interfaces and objects in the ViewModelLocator class ViewModelLocator { static ViewModelLocator() { ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default); if (ViewModelBase.IsInDesignModeStatic) { SimpleIoc.Default.Register<IDataService, Design.DesignDataService>(); } else { SimpleIoc.Default.Register<IDataService, DataService>(); } SimpleIoc.Default.Register<MainViewModel>(); SimpleIoc.Default.Register<SecondViewModel>(); } public MainViewModel Main { get { return ServiceLocator.Current.GetInstance<MainViewModel>(); } } } 2) Every object is a singleton by … Read more

What is a ViewModelLocator and what are its pros/cons compared to DataTemplates?

Intro In MVVM the usual practice is to have the Views find their ViewModels by resolving them from a dependency injection (DI) container. This happens automatically when the container is asked to provide (resolve) an instance of the View class. The container injects the ViewModel into the View by calling a constructor of the View … Read more

Issue with DependencyProperty binding

The primary problem is that you set your UserControl’s DataContext to itself in its constructor: DataContext = this; You should not do that, because it breaks any DataContext based Bindings, i.e. to a view model instance that is provided by property value inheritance of the DataContext property Instead you would change the binding in the … Read more

tech