Who's signing the propertyChanged event?
-
There's a piece of code taken from the resource. http://howtowpf.ru/mvvm-dlya-chaynikov/
He had a question about the event.
PropertyChanged
using System.ComponentModel; using System.Windows.Input;
namespace firstMVVMapp
{
public class ViewModel : INotifyPropertyChanged
{
//Поля
private int _summa;
//Свойства
public int A { get; set; }
public int B { get; set; }
public int Summa
{
get { return _summa; }
set
{
if (_summa != value)
{
_summa = value;
OnPropertyChanged("Summa");
}
}
}
//Команды
public ICommand ClickCommand { get; set; }
//реализация INotifyPropertyChanged
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
//Конструктор
public ViewModel()
{
ClickCommand = new RelayCommand(arg => ClickMethod());
}
//Методы
private void ClickMethod()
{
Summa = A + B;
}
}
}
The question is, in fact, that no one has signed the event. And as far as I'm concerned, it's in method.
OnPropertyChanged
shall not pass the inspectionnull
♪ But somehow it passes well. There's no signature on the code.+=
to this event. Why not?null
?
-
Objects are signed. http://msdn.microsoft.com/en-us/library/system.windows.data.binding.aspx when you make the connections. Try to realize this event in a clear way, put a brakepoint in the section.
add
and look at the glasses:private event PropertyChangedEventHandler propertyChanged; private object objectLock = new Object();
public event PropertyChangedEventHandler PropertyChanged
{
add
{
lock (this.objectLock)
{
this.propertyChanged += value;
}
}
remove
{
lock (this.objectLock)
{
this.propertyChanged -= value;
}
}
}