ComboBox
for each TODO item in code. However doing it this way has a few disadvantages:Models
directory in your project:Database
and put this in a Services
directory:TodoListView
and so the associated view model is going to be called TodoListViewModel
. Place this class in the ViewModels
directory in your project:TodoItem
models in its constructor and puts them into an ObservableCollection
which is exposed via an Items
property.ViewModelBase
class. The importance of this will become clear shortly.TodoListViewModel
requires a collection of TodoItem
models to be passed to its constructor, but where do these items come from? Where is TodoListViewModel
created?MainWindow
(created by the template)MainWindowViewModel
(created by the template)TodoListView
(created by us)TodoListViewModel
(created by us)TodoListView
is a child of MainWindow
). This might give us a clue: MainWindowViewModel
should create the TodoListViewModel
!MainWindowViewModel.cs
file to look like this:OnFrameworkInitializationCompleted
method in App.axaml.cs
to create an instance of Database
and pass it to MainWindowViewModel
: