MVVM for WPF (Step3) & mdash; use Prism (1), wpfmvvm

Source: Internet
Author: User

MVVM for WPF (Step 3) -- use Prism (1), wpfmvvm

When using the WPF-MVVM development, the implementation of the notification interface, DelegateCommand is relatively less used, we are more of a third-party MVVM framework, among them, Microsoft's own team provides the Prism framework, which has many functions and I am learning little about it. I will briefly introduce the use of this framework.

Note: Prism version 4.1 is used here

Prism helps us implement the INotifyPropertyChanged interface first. RaisePropertyChanged not only implements the use of string notifications, but also Lambda expressions, which provides some convenience in code refactoring...

Secondly, Prism helps us implement the ICommand interface, which can be implemented using its DelegateCommand.

The following is a brief code:

Class TestViewModel: icationicationobject {private string teststr; // <summary> // the string to be notified /// </summary> public string TestStr {get {return 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> // method executed by testcommand /// </summary> private void Test () {I ++; testStr = I. toString () ;}/// <summary> /// test whether the command is available /// </summary> /// <returns> </returns> private bool CanTest () {return true ;}}

 

DelegateCommand in Prism is used here, which is used without passing parameters. The next article describes how to use DelegateCommand <T> to create a Command that can pass parameters.

 

Project code hosting address: https://wpfmvvm.codeplex.com/

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.