-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BindableBase.cs
30 lines (27 loc) · 1.08 KB
/
BindableBase.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.CompilerServices;
namespace SynchronizedEvents
{
public abstract class BindableBase : INotifyPropertyChanged
{
private readonly ContextPropertyChanged _propertyChanged = new ContextPropertyChanged();
public event PropertyChangedEventHandler PropertyChanged
{
add => _propertyChanged.Add(value);
remove => _propertyChanged.Remove(value);
}
protected bool SetProperty<T>(ref T originalValue, T newValue, [CallerMemberName] string propertyName = null)
{
if (!EqualityComparer<T>.Default.Equals(originalValue, newValue))
{
originalValue = newValue;
RaisePropertyChanged(propertyName);
return true;
}
return false;
}
protected async void RaisePropertyChanged([CallerMemberName] string propertyName = null)
=> await _propertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName)).ConfigureAwait(false);
}
}