问题描述
所以,我的课程是由EF自动生成的:
So, my classes are auto-generated by 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。这是可能的,而不是编辑这个生成的类?
When one of the properties change, I'd like to do a notifypropertychange. Is this possible somehow without editing this generated class?
推荐答案
这是可能的,但我强烈建议不要这样做!
在你的模型中添加INotifyPropertyChanged将导致一个
不好的分离问题。
It would be possible, but I strongly suggest to not do this!Adding INotifyPropertyChanged in your model will lead to abad separation of concerns.
使用事件突出显示模型已更改。
看看这是如何工作的:
Use events to highlight that the model has changed.Have a look here to see how this works: MSDN on standard event pattern
甚至更好:
在您的viewmodel中,实现INotifyProperty已更改。
让您的ViewModel听从模型中的事件,调整数据
并通过INotifyPropertyChanged将其推送到您的视图
In your viewmodel, implement INotifyProperty changed.Let your ViewModel than listen to the events from your model, adapt the dataand push it to your view through INotifyPropertyChanged
这篇关于在生成的EF类中添加INotifyPropertyChange的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!