When using WPF-MVVM development, the implementation of their own notification interface, Delegatecommand relatively less use, we are more use of the third-party MVVM framework, which Microsoft's own team provided by the PRISM framework, this framework is more functional, I now learn a limited, For the time being, let's introduce simple use.
Note: Prism version 4.1 is used here
Prism first convenient for us is to help us implement the INotifyPropertyChanged interface, where raisepropertychanged not only realizes the use of string notifications, but also realizes the lambda expression, which provides some convenience in code refactoring ...
Second, Prism helps us implement the ICommand interface, which can be implemented using its delegatecommand.
The following is a summary code:
Class Testviewmodel:notificationobject {private string teststr; <summary>///For notification string///</summary> public string Teststr {get {R} Eturn Teststr; } set {teststr = value; raisePropertyChanged (() =>teststr); }}///<summary>///TEST command///</summary> public ICommand Testcommand {get ; Set } public Testviewmodel () {Testcommand = new Delegatecommand (test,cantest); } int i = 0; <summary>///Testcommand Execution method///</summary> private void Test () { i++; Teststr = i.ToString (); }///<summary>//Testcommand available///</summary>//<returns></returns > private bool Cantest () {return true; } }
The Delegatecommand in Prism is used here, which is used to not pass parameters, and the following describes the use of delegatecommand<t> to create a command that can pass parameters.
Project code managed Address: https://wpfmvvm.codeplex.com/
WPF MVVM (STEP3)-Using prism (1)