-
Notifications
You must be signed in to change notification settings - Fork 8k
/
BindableBase.cs
35 lines (31 loc) · 1.04 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
31
32
33
34
35
using System;
using System.ComponentModel;
using System.Runtime.CompilerServices;
namespace Notifications.Helpers
{
/// <summary>
/// From http://danrigby.com/2012/04/01/inotifypropertychanged-the-net-4-5-way-revisited/
/// </summary>
public abstract class BindableBase : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
protected bool SetProperty<T>(ref T storage, T value, [CallerMemberName] String propertyName = null)
{
if (Equals(storage, value))
{
return false;
}
storage = value;
this.OnPropertyChanged(propertyName);
return true;
}
protected void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChangedEventHandler eventHandler = this.PropertyChanged;
if (eventHandler != null)
{
eventHandler(this, new PropertyChangedEventArgs(propertyName));
}
}
}
}