开发者

How can a Command(derived from a ICommand) access a viewmodel

I have a Command - AddCommand , which has to add the users to the database. The business logic to add to database is in the ViewModel methods (Add_to_Db, Delete_from_Db). But i need the command(AddCommand) to acces the view开发者_运维技巧model(for all the methods) without passing the viewmodel as CommandParameter from XAML.

As i need to pass other info(UserInfo) as CommandParameter to the command. What are the ways a command can have access to the related ViewModel.


Use DelegateCommand.

References:

MVVM Infrastructure: DelegateCommand

How to implement a reusable ICommand

All you do is pass a method of you ViewModel class to this DelegateCommand that gets executed when command is executed. That way you can access your ViewModel. And it's reusable and widely used approach, too.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜