I have two view models: ListItemViewModel
and ListViewModel
. My ListViewModel
contains many ListItemViewModel
objects, when I try to delete one item, I'm binding DeleteCommand
in ListItemViewModel
like this:
public IMvxCommand DeleteCommand => new MvxCommand(DeleteCommandHandler);
The problem is that DeleteCommandHandler
is in ListViewModel
... How can I call handler from another view model?
UPDATE 1
Got the question why do I need this. The reason of my question is that in handler I will need to make an API call which requires dependency injection, but my ListItemViewModel
must have default empty constructor because of automapper, so all the business logic I want to move to "parent view model" which is ListViewModel
Try using messaging services to communicate b/w different viewmodels. In your case, the DeleteCommandHandler
will trigger in ListItemViewModel
and then will pass a message to ListViewModel
sending details of item deleted.
Refer to the link on how to implement Messaging.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.