INotifyPropertyChanged
在WPF MVVM模式开发中,使用他可以通知数据更新
-
定义一个
NotifyBase
工具类,继承INotifyPropertyChanged
复制代码1
2
3
4
5
6
7
8
9
10public class NotifyBase : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; public void DoNotify([CallerMemberName] string name = "") { PropertyChanged?.Invoke(this,new PropertyChangedEventArgs(name)); } }
-
在绑定的Model中继承定义好的
NotifyBase
复制代码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
47public class SongModel : NotifyBase { /// <summary> /// 歌曲url /// </summary> private string _songUrl; public string SongUrl { get { return this._songUrl; } set { _songUrl = value; DoNotify(); } } /// <summary> /// 本地下载后的mp3路径 /// </summary> private string _localSongUrl; public string LocalSongUrl { get { return this._localSongUrl; } set { _localSongUrl = value; DoNotify(); } } /// <summary> /// 歌曲图片 /// </summary> private string _picUrl; public string PicUrl { get { return this._picUrl; } set { _picUrl = value; DoNotify(); } } }
最后
以上就是激动鸡翅最近收集整理的关于INotifyPropertyChanged通知,mvvm更新数据的全部内容,更多相关INotifyPropertyChanged通知内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复