mvvm - Difference between Set() and RaisePropertyChanged() -


I'm reading this mvvm lighting framework for learning. I download source code Friend.cs.

My question is that some set method of different properties is implemented differently. For example, for the first name setter, why should I want to 'ref' the keyword for _firstName?

  set (first name, property name, ref first, name);   

and setter for DateOfBirthString "

  RaisePropertyChanged ((=) = DateOfBirth);   

When LINQ expression Will be evaluated

  namespace MyFriends.Model {[SimpleSerialize] public class friend: ObservableObject {/// & lt; summary & gt; /// & lt; see cref = "FirstName" /> Property Name ///./lt; / summary> Public String String FirstNamePropertyName = "First", Private string _firstName; /// & lt; Summary & gt; /// Set and The first asset gets / changes in the ./payer that the value of the property is Proper Set tychange_image_product.php/TrChanged event./satellite.aspx [SimpleSerialize (FieldName = "first_name")] Public string FirstName {get {return_firstName;} set {set (FirstNamePropertyName, ref _firstName, value);}} / // and & lt; summary & gt; /// & lt; see cref = "last name" /> property name ///./lt; / summary & gt; public constant string LastNamePropertyName = "last name" , Private string _lastName; /// & lt; Summary & gt; /// Set and get the tag property property / / Change the value of that property Increase the event by changing the property. /// & lt; / Summary & gt; [Ordinary serialize (filename = "last_name")] public string lastime {get {return _lastName; } Set {Set (LastNamePropertyName, Refresh_Lostname, Value); }} /// & lt; Summary & gt; ///; & Lt; See cref = "DateOfBirth" /> Property Name /// & lt; / Summary & gt; Public construction string dateofferpropertynet = "dateoff"; Private string _dateOfBirthString; /// & lt; Summary & gt; /// Set and DateOfBirth attribute gets. / / Increase the event by changing the property to change the value of that property. /// & lt; / Summary & gt; [Simple serialize (filename = "birthday")] public string dateoffbirthstring {get {return_dateOfBirthString; } Set {_dateOfBirthString = value; RaisePropertyChanged (() => DateOfBirth); }} Public Datetime Dateof {meet (if string is new neural blank (_dateOfBirthString)} Return {DateTime.MinValue; } Return date Purse eXact (dateoffbirthstring, "D", culture info, invariant culture); } Set {_dateOfBirthString = value.ToString ("d", CultureInfo.InvariantCulture); }} Private string _imageUrl; [SimpleSerialize (filename = "picture")] Public string image URL {get {return_imageUrl; } Set {_imageUrl = value; RaisePropertyChanged ((= = Imagery); }} Public Ure ImageURI {Get New Yuri (_imageUrl); The difference between those two methods is that set . The  method  _firstName  changes the old value of the field and then gives rise to , is the PropertyChanged  event, whereas  RaisePropertyChanged  only  Gives birth to property by changing  event.  

You would want to use the set method in most cases, because it helps wrap asset allies by wrapping everyone, which should usually be done in only one method. Within the setter of the property:

  1. It updates the value of the passed fields and overwrites it with the contents of value , and then Li> To change the idea about this update, PropertyChanged Lets the event.

    The field needs to be passed by reference (thus ref_firstName ) is that the contents of the field be set to set Do not need inner, but the field itself is Ctually Update

    RaisePropertyChanged method is useful when updating a property also affects additional properties. In this case, the contents of these properties need to be updated manually, then < It can be said to show the code> RaisePropertyChanged which of the properties has actually been changed.

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -