所以,我的类是由 EF 自动生成的:
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated from a template.
//
// Manual changes to this file may cause unexpected behavior in your application.
// Manual changes to this file will be overwritten if the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace Testje.Models
{
using System;
using System.Collections.Generic;
public partial class Ploeg
{
public Ploeg()
{
}
public int Id { get; set; }
public string Naam { get; set; }
public string Icon { get; set; }
}
}
当其中一个属性发生变化时,我想做一个 notifypropertychange。如果不编辑这个生成的类,这是否可能以某种方式实现?
最佳答案
这是可能的,但我强烈建议不要这样做! 在您的模型中添加 INotifyPropertyChanged 将导致 关注点分离不佳。
使用事件来突出显示模型已更改。 在这里看看它是如何工作的:MSDN on standard event pattern
或者更好:MSDN cites Albahari Bros on the event pattern
在您的 View 模型中,实现 INotifyProperty 已更改。 让您的 ViewModel 监听模型中的事件,调整数据 并通过 INotifyPropertyChanged 将其推送到您的 View
关于c# - 在生成的 EF 类中添加 INotifyPropertyChange,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13443162/