-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathViewModelBase.cs
62 lines (55 loc) · 1.76 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
using Prism.Mvvm;
using System.ComponentModel;
namespace IgOutlook.Core
{
public class ViewModelBase : BindableBase
{
private string _title;
public string Title
{
get { return _title; }
set { SetProperty(ref _title, value); }
}
private string _iconSource;
public string IconSource
{
get { return _iconSource; }
set { SetProperty(ref _iconSource, value); }
}
public void UpdateTitleOnPropertyChanged(INotifyPropertyChanged source, string propertyName, string concatedString = "", string nullValue = "")
{
source.PropertyChanged += (s, a) =>
{
if (a.PropertyName == propertyName)
{
var value = (string)source.GetType().GetProperty(propertyName).GetValue(source);
if (string.IsNullOrEmpty(value))
Title = nullValue + concatedString;
else
Title = value + concatedString;
}
};
}
public void HookOnPropertyChanged(INotifyPropertyChanged source, string propertyName, System.Action action)
{
source.PropertyChanged += (s, a) =>
{
if (a.PropertyName == propertyName)
{
action.Invoke();
}
};
}
//public void HookOnPropertyChanged(INotifyPropertyChanged source, System.Action action)
//{
// source.PropertyChanged += (s, a) =>
// {
// action.Invoke();
// };
//}
public void RefreshTitle()
{
RaisePropertyChanged("Title");
}
}
}