如果记录更改,如何更改 DataGrid 行颜色
如果可能的话,我想通过绑定实现以下目标...
我有一个绑定到 ObservableCollection 的 WPF DataGrid
public class Product
{
public string Code { get; set; }
public string Desc { get; set; }
public bool Updated { get; set; }
}
我的网格 DataContext 设置为可观察集合。
我想要实现的目标...
- 当用户更改数据网格中的一行时,产品的更新字段将更改为“true”。
- 因此,我可以以某种方式绑定网格的行颜色以显示不同的颜色,这将向用户表明该行尚未保存。
我认为我需要实现 INotifyPropertyChanged 来完成此任务,但不确定具体如何执行。此外,网格上是否有绑定属性来确保 UI 上所做的更改更新后备存储?
干杯。
I would like to achieve the follwing via binding if possible...
I have a WPF DataGrid bound to an ObservableCollection
public class Product
{
public string Code { get; set; }
public string Desc { get; set; }
public bool Updated { get; set; }
}
My grids DataContext is is set to the observable collection.
What I would like to achieve...
- When the user changes a row in the datagrid the Updated field of the Product is changed to "true".
- As a result of this I can somehow bind the grid's row color to display a different colour which will indicate to the user that this row hasnt yet been saved.
I think that I will need to implement INotifyPropertyChanged to accomplish this but not certain on exactly how to do it. Additionally, is there a binding property on the grid to ensure that changes made on the UI update the backing store?
Cheers.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的
Product
类应实现INPC
所以到Updated
的绑定已更新。您还可以更改所有属性的设置器,将
Updated
设置为true
。您可以在属性上触发:
Your
Product
class should implementINPC
so bindings toUpdated
are updated.You can additionally change the setters of all properties to set
Updated
totrue
.You can trigger on the property: