Silverlight 4 MVVM development method (2)

Source: Internet
Author: User

From http://www.dotblogs.com.tw/help/archive/2010/07/29/16883.aspx

 

After finishing the address book, Xiao Hei showed the address book to his boss Xiao Ke to show off his face. He was also taken for granted a gun!

"Why is all the list on the left changed after each ADD operation?

Does anyone enter the age? Is it necessary to modify it once a year?

How can I modify the changes ??』

Xiao Hei had to touch his nose and go back to discuss with Kama.

After each addition, the list is changed to the last project, which is obviously a problem with data processing by Xiao Hei,

For age problems, add a column to enter the Birthday, the column name is Birthday, and then calculate the age,

As for the changes, kama said that he would design a new interface.

 

After the statement is made, Tom and Kama will modify the rules respectively!

First, Tom looked at the code and found that the Add function added the same object every time. No wonder there will be problems.

So he changed Add to the following:

  1: private void Add() { 
  2: if (_NewUserCard != null ) { 
  3: UserCardList.Add(_NewUserCard); 
  4: NewUserCard = new UserCard(); 
  5: } 
  6: } 

Then he adds a birthday field to UserCard and automatically calculates the age when the birthday changes!

  1: private DateTime _Birthday; 
  2: public DateTime Birthday { 
  3: get { return _Birthday; } 
  4: set { 
  5: _Birthday = value ; 
  6: Update( "Birthday" ); 
  7: Age = DateTime.Now.Year - _Birthday.Year; 
  8: } 
  9: } 

 

Then Tom believes in his program skills, so he goes to bed without testing!

What about Kama? He only needs to know how to add a date column for his Birthday, which is called Birthday,

You can use the Blend Technology for other interface operations!

At last, kama made the following style.

 

One of the major advantages of developing Silverlight or WPF applications using MVVM is that the program logic does not need to be bound by the interface, and the program development and interface development can be parallel at the same time.

If you want to communicate with the database in the future, accessing the address book will not affect the development of the front-end interface, and the front-end will not affect the backend code if you want to change the skin-and-effect.

DEMO_MVVM_2.rar

 

 

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.