-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathViewModelBase.cs
81 lines (64 loc) · 2.1 KB
/
ViewModelBase.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
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
70
71
72
73
74
75
76
77
78
79
80
81
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Windows;
using WpfApp.Annotations;
namespace WpfApp.Framework.Core
{
public abstract class ViewModelBase : PipeViewModel, INotifyPropertyChanged, ISaverData
{
#region INotifyPropertyChanged
public event PropertyChangedEventHandler PropertyChanged;
[NotifyPropertyChangedInvocator]
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
#endregion
public static readonly bool IsDesignerMode = DesignerProperties.GetIsInDesignMode(new DependencyObject());
public override void OnPreInit()
{
}
public override void OnInit()
{
}
public override void OnLoaded()
{
}
public override void OnFinished()
{
}
public override bool OnFinishing()
{
return true;
}
public object this[string key]
{
get { return _data[key]; }
set
{
object val;
if (_data.TryGetValue(key, out val) && val == value) return;
_data[key] = value;
OnPropertyChanged(System.Windows.Data.Binding.IndexerName);
}
}
public object this[string key, object defaultValue]
{
get
{
object result;
return _data.TryGetValue(key, out result) ? result : this[key] = defaultValue; // save current defaultValue if not exists
}
set { this[key] = value; } // for Mode=TwoWay
}
#region ISaverData
object ISaverData.GetAllData() => _data;
void ISaverData.SetAllData(object data)
{
_data = data == null ? new Dictionary<string, object>() : (IDictionary<string, object>) data;
}
private IDictionary<string, object> _data;
#endregion
}
}