How do I pass the information from View to ViewModel with DelegateCommand?

前端 未结 5 1612
感情败类
感情败类 2021-02-02 18:16

In my View, I have a button.

When the user clicks this button, I want to have the ViewModel save the context of the TextBlock in the database.



        
5条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-02 18:45

    Check out this MSDN article by Josh Smith. In it, he shows a variation of DelegateCommand that he calls RelayCommand, and the Execute and CanExecute delegates on RelayCommand accept a single parameter of type object.

    Using RelayCommand you can pass information to the delegates via a CommandParameter:

    Update

    Looking at this article, it appears that there is a generic version of DelegateCommand which accepts a parameter in a similar way. You might want to try changing your SaveCommand to a DelegateCommand and change your Save and CanSave methods so that they take a MyObject parameter.

提交回复
热议问题