WPF-dataGrid dynamic update

WPF-dataGrid dynamic update

WPF-dataGrid dynamic update Introduction: Problem: In WPF, ObservableCollection is used as the data source of the dataGrid, and it is found that updating the data does not trigger the update of the dataGrid By MaQaQ 2023-11-22 Analysis: 1. ObservableCollection will trigger update notifications when elements of the collection are added, removed, or cleared. Changes to the properties of elements in the collection will not trigger notifications. 2. If you want to trigger a notification when updating data, you can implement the INotifyPropertyChanged interface in the T class, so that when its properties change, the notification will be triggered and the dataGrid will be updated. The implementation is as follows:  1. xml    2. CS medium Define ObservableCollection<Model> memberData = new ObservableCollection<Model>(); Model is defined as follows: public class Model : INotifyPropertyChanged { protected int span> id; protected string span> name; protected bool span> online; protected bool span> registered; public int span> ID { get => id; set => id = value; } public string span> Name { get => name; set => name = value; } public bool span> IsOnline { get => online ; set { if (online != value) { online = value; OnPropertyChanged(“IsOnline “); } } }…

WPF-dataGrid dynamic update

WPF-dataGrid dynamic update

WPF-dataGrid dynamic update Introduction: Problem: In WPF, ObservableCollection is used as the data source of the dataGrid, and it is found that updating the data does not trigger the update of the dataGrid By MaQaQ 2023-11-22 Analysis: 1. ObservableCollection will trigger update notifications when elements of the collection are added, removed, or cleared. Changes to the properties of elements in the collection will not trigger notifications. 2. If you want to trigger a notification when updating data, you can implement the INotifyPropertyChanged interface in the T class, so that when its properties change, the notification will be triggered and the dataGrid will be updated. The implementation is as follows:  1. xml    2. CS medium Define ObservableCollection<Model> memberData = new ObservableCollection<Model>(); Model is defined as follows: public class Model : INotifyPropertyChanged { protected int span> id; protected string span> name; protected bool span> online; protected bool span> registered; public int span> ID { get => id; set => id = value; } public string span> Name { get => name; set => name = value; } public bool span> IsOnline { get => online ; set { if (online != value) { online = value; OnPropertyChanged(“IsOnline “); } } }…

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索