Window.Contentproperty to the
MainWindowViewModel.Listproperty which is an instance of
TodoListViewModelbut the window is displaying a
TodoListView! What's happening here? How is a view being displayed when the window content is a view model?
ViewLocator.cswhich was a file added by the template:
Match(object data)looks at the data and if the data inherits from
Buildshould be called
Build(object data)takes the fully qualified name of the data's type and replaces the string
"ViewModel"with the string
"View". It then tries to get a type that matches that name. If a matching type is found, it creates an instance of the type and returns it
ViewLocatoris present in
Window) has its
Contentproperty set to a non-control, it searches up the tree of controls for a
DataTemplatethat matches the content data. If no other
DataTemplatematches the data it will eventually reach the
ViewLocatorin the application data templates which will do its business and return an instance of the corresponding view.