-
Notifications
You must be signed in to change notification settings - Fork 1
NotifyObject
Namespace: ES.Tools.MVVM (ES.Tools.Core)
The NotifyObject is a base class for all classes that need to raise PropertyChanged events. It implements interface INotifyPropertyChanged.
This is mainly used on the ViewModel level when using WPF data binding to notify the View when properties in the ViewModel have changed.
The example consists of an Employee class which inherits from NotifyObject. Whenever the properties FirstName or LastName is changed, a PropertyChanged. event is triggered by calling OnPropertyChanged.
Also a PropertyChanged event it triggeredd for the property FullName.
Calling OnPropertyChanged without arguments automatically uses the name of the surrounding property.
public class Employee : NotifyObject
{
private string _firstName;
private string _lastName;
public string FirstName
{
get => _firstName;
set
{
if (_firstName != value)
{
_firstName = value;
OnPropertyChanged();
OnPropertyChanged(nameof(FullName));
}
}
}
public string LastName
{
get => _lastName;
set
{
if (_lastName != value)
{
_lastName = value;
OnPropertyChanged();
OnPropertyChanged(nameof(FullName));
}
}
}
public string FullName => $"{LastName}, {FirstName}";
}See also ViewModel.
-
Infrastructure
-
MVVM
-
Adorners
-
Behaviors
-
Controls
-
Converters
-
Effects
-
Infrastructure