-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathObservable.cs
More file actions
69 lines (59 loc) · 2.02 KB
/
Observable.cs
File metadata and controls
69 lines (59 loc) · 2.02 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Windows.Input;
namespace PAENN2
{
/// <summary>
/// Abstract class implementing the INotifyPropertyChanged interface.
/// </summary>
public abstract class Observable : INotifyPropertyChanged
{
// Broadcasts the change in property so it can be picked up by the WPF controls.
public event PropertyChangedEventHandler PropertyChanged;
/// <summary>
/// Broadcasts the change in a given property.
/// </summary>
/// <param name="Property">The property's name.</param>
public void NotifyPropertyChanged(string Property)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(Property));
}
/// <summary>
/// Notifies the change in a property.
/// </summary>
/// <typeparam name="T">The property type.</typeparam>
/// <param name="property">The property.</param>
/// <param name="field">The private backing field.</param>
/// <param name="value">The newly assigned value.</param>
protected void ChangeProperty<T>(ref T field, T value, [CallerMemberName] string propertyName = null)
{
if (!EqualityComparer<T>.Default.Equals(field, value))
{
field = value;
NotifyPropertyChanged(propertyName);
}
}
}
/// <summary>
/// Basic command delegate class, implementing the ICommand interface.
/// </summary>
public class DelegateCommand : ICommand
{
private readonly Action<object> execute;
public event EventHandler CanExecuteChanged;
public DelegateCommand(Action<object> action)
{
execute = action;
}
public void Execute(object parameter)
{
execute(parameter);
}
public bool CanExecute(object parameter)
{
return true;
}
}
}