Wpf mvvm uses the Prism framework to transmit parameters, wpfmvvm

Source: Internet
Author: User

Wpf mvvm uses the Prism framework to transmit parameters, wpfmvvm

Recently I learned how to use the MVVM of WPF. In practice, I found that ComandParameter does not know how to pass it to ViewModel. I found some solutions on the Internet. Most of them use IComand to solve the problem as follows:

// The purpose is to pass in the selected row of the DataGrid to delete the public ICommand DelCmd {get {return new DelegateCommand <object> (para) =>{ SelectStudet = (Students) para; // Delete student DelStudent ();});}}

The above code can solve my problem, but I think that since Prism is a mature framework, it should not be impossible to implement such passing parameters, then I took a closer look at the class where the DelegateCommand of Prism is located and found that it has a definition of DelegateCommand <T>. Then the problem was solved as follows:

// Command to define public DelegateCommand <object> DeleCmd {get; set ;}
// Command to initialize public MainWindowViewModel () {this. getAllStudents (); DeleCmd = new DelegateCommand <object> (new Action <object> (para) =>{ DeleStudent (para );}));}

This will solve the problem of passing Parameters Using Prism.

Ps: although this is not a profound problem, it reflects some of my personal shortcomings: I always seek help from du Niang when encountering problems, in order to improve efficiency in actual project development, this is understandable, but you still need to think more and cultivate your ability to solve problems in your daily study. I would like to write this article to encourage myself, we also hope that most new R & D personnel will find other people's solutions without any problems. (If the words in this article are inaccurate, thank you for pointing them out. After all, I am also a dish. I hope you can give me more advice. Haha !)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.