-
Notifications
You must be signed in to change notification settings - Fork 21
/
NotifyProperty.cs
44 lines (38 loc) · 1.17 KB
/
NotifyProperty.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
// lindexi
// 15:58
using System;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using Windows.ApplicationModel.Core;
using Windows.UI.Core;
namespace UwpConvertSimplifie.ViewModel
{
/// <summary>
/// 提供继承通知UI改变值
/// </summary>
public class NotifyProperty : INotifyPropertyChanged
{
public NotifyProperty()
{
}
public void UpdateProper<T>(ref T properValue, T newValue, [CallerMemberName] string properName = "")
{
if (Equals(properValue, newValue))
{
return;
}
properValue = newValue;
OnPropertyChanged(properName);
}
public async void OnPropertyChanged([CallerMemberName] string name = "")
{
PropertyChangedEventHandler handler = PropertyChanged;
await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
() =>
{
handler?.Invoke(this, new PropertyChangedEventArgs(name));
});
}
public event PropertyChangedEventHandler PropertyChanged;
}
}