curiouswebster
asked on
Understanding the guts of Model-View-ViewModel
I am new to Model-View-ViewModel and wonder if the .NET Framework triggers whether a property has changed it's value or not.
I see that inside the Set of properties, the
base.OnPropertyChanged("Is Selected") ; (for example)
is called. If the value did not change, does the .NET Framework then ignore this event?
What confuses me is this line of code:
PropertyChangedEventHandle r handler = this.PropertyChanged;
if (handler != null)
What ever makes PropertyChanged not null?
This part, if done by the .NET Framework, I can then understand. Otherwise I do not see in the demo program where this is done...
Here is the demo I am using:
http://msdn.microsoft.com/en-us/magazine/dd419663.aspx
Thanks,
newbieweb
I see that inside the Set of properties, the
base.OnPropertyChanged("Is
is called. If the value did not change, does the .NET Framework then ignore this event?
What confuses me is this line of code:
PropertyChangedEventHandle
if (handler != null)
What ever makes PropertyChanged not null?
This part, if done by the .NET Framework, I can then understand. Otherwise I do not see in the demo program where this is done...
Here is the demo I am using:
http://msdn.microsoft.com/en-us/magazine/dd419663.aspx
Thanks,
newbieweb
/// </summary>
public event PropertyChangedEventHandler PropertyChanged;
/// <summary>
/// Raises this object's PropertyChanged event.
/// </summary>
/// <param name="propertyName">The property that has a new value.</param>
protected virtual void OnPropertyChanged(string propertyName)
{
this.VerifyPropertyName(propertyName);
PropertyChangedEventHandler handler = this.PropertyChanged;
if (handler != null)
{
var e = new PropertyChangedEventArgs(propertyName);
handler(this, e);
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
See, that's what is puzzling me about the code I posted. I searched the whole project for
"new Property" with Match Whole Word not checked.
I got one instance:
var e = new PropertyChangedEventArgs(p ropertyNam e);
but if you look at the code that only gets called when this.PropertyChanged is not null.
if (handler != null)
I don't get it. Unless in this demo the code is there for this but not used?
"new Property" with Match Whole Word not checked.
I got one instance:
var e = new PropertyChangedEventArgs(p
but if you look at the code that only gets called when this.PropertyChanged is not null.
if (handler != null)
I don't get it. Unless in this demo the code is there for this but not used?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Oh, I see. So based on the types of bindings I have made with controls, it may make these kinds of decisions? if not that, then what kinds of things might influence it?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks. It's not so mysterious any more...
ASKER
How does one subscribe to the event?