Recently learning to use the WPF MVVM, in practice found comandparameter do not know how to pass to ViewModel, find some friends on the Internet solution most use Icomand to solve the following:
The purpose here is to pass the DataGrid selection row in to delete public ICommand delcmd { get { return new Delegatecommand<object > ((para) = { Selectstudet = (Students) para; Delete student delstudent ();} ); } }
The above code can solve the problem I encountered, but I think since Prism is a mature framework, should not appear this kind of communication can not achieve the problem ah, then I took a closer look at the prism of the Delegatecommand of the class, Found that he had a delegatecommand<t> definition, and then the problem was solved as follows:
// Command Definition Public delegatecommand<Objectgetset; }
public Mainwindowviewmodel () { this. Getallstudents (); New delegatecommand<Object> (new action<object> ((para) = { Delestudent (para); }); }
This solves the problem of using prism to pass parameters.
PS: Although this is not a high-level problem, but this reflects some of my personal shortcomings: always in the face of the problem when to turn to the mother, in the actual project development in order to efficiency, which is understandable, but in the ordinary of their own study also need to think a lot, to cultivate their ability to solve problems, I would like to encourage myself by writing this article, and I hope that most new developers will not have the idea of finding someone else's solution when they encounter problems. (If the text is inaccurate, thank you all can point out, after all, I am also a dish, I hope we have a lot of advice, haha!) )
WPF MVVM uses the prism framework to pass parameters