As I realized the command is defined in employeelistviewmodel
.
When you don't set the DataContext
of EmployeeList
, it inherits it from his parent. Because the DataContext
of the parent is employeelistviewmodel
and this view-model contains the command, the Command
property of your button is set with the command. If you set the DataContext
of EmployeeList
to another object that doesn't contain the command, the Command
property of your button isn't set and, when you click the button, no command is executed.
For solving the problem, you can move the button from EmployeeList
to EmployeeView
.
If you have to keep the button in EmployeeList
, you can create another view-model that contains SelectedEmployee
(the original value you set as DataContext
) and the wanted command and, set it as the DataContext
of EmployeeList
. In EmployeeList
, use SelectedEmployee
and the command appropriately.