MVVM子属性更改检测
我的问题如下: 我正在使用MVVM模式,我想知道如何检测子属性的更改 我有一个文本框:MVVM子属性更改检测,mvvm,entity,Mvvm,Entity,我的问题如下: 我正在使用MVVM模式,我想知道如何检测子属性的更改 我有一个文本框: <TextBox Name="Descripcion" Text="{Binding AccionActual.Descripcion,Mode=TwoWay}" /> Accion实体定义为: public partial class Accion : Entity { public Accion() { this.Accion
<TextBox Name="Descripcion" Text="{Binding AccionActual.Descripcion,Mode=TwoWay}" />
Accion实体定义为:
public partial class Accion : Entity
{
public Accion()
{
this.AccionesDocumentos = new HashSet<AccionDocumento>();
}
public int IdAccion { get; set; }
public int IdEmpleado { get; set; }
public string Descripcion { get; set; }
public string DescripcionDetalle { get; set; }
public bool Finalizada { get; set; }
public Nullable<int> IdExpediente { get; set; }
public Nullable<int> IdOrdenTrabajo { get; set; }
public bool Facturable { get; set; }
public Nullable<short> GestComAlbaranAño { get; set; }
public Nullable<short> GestComAlbaranEmpresa { get; set; }
public Nullable<int> GestComAlbaranNumero { get; set; }
public bool Facturado { get; set; }
public bool ComputarHorasACliente { get; set; }
public string DescripcionInterna { get; set; }
public virtual Aplicacion Aplicacione { get; set; }
public virtual AplicacionModulo AplicacionesModulo { get; set; }
public virtual Cliente Cliente { get; set; }
public virtual ClienteContacto ClientesContacto { get; set; }
public virtual Empleado Empleado { get; set; }
public virtual Expediente Expediente { get; set; }
public virtual OrdenTrabajo OrdenesTrabajo { get; set; }
public virtual ICollection<AccionDocumento> AccionesDocumentos { get; set; }
}
公共部分类帐户:实体
{
公众谘询(
{
this.AccionesDocumentos=new HashSet();
}
公共int-IdAccion{get;set;}
public int-IdEmpleado{get;set;}
公共字符串描述符{get;set;}
公共字符串descriptiondetalle{get;set;}
公共bool{get;set;}
公共可为空的IDExpedinte{get;set;}
公共可空IdOrdenTrabajo{get;set;}
公共布尔可制作{get;set;}
公共可空的GestComAlbaranAño{get;set;}
公共可为空的GestComAlbaranEmpresa{get;set;}
公共可为空的GestComAlbaranNumero{get;set;}
公共bool Facturado{get;set;}
公共bool ComputarHorasaClient{get;set;}
公共字符串descriptionInterna{get;set;}
公共虚拟应用程序应用程序{get;set;}
公共虚拟AplicacionModulo{get;set;}
公共虚拟客户端客户端{get;set;}
公共虚拟客户联系人o客户联系人{get;set;}
公共虚拟模板{get;set;}
公共虚拟权宜之计{get;set;}
公共虚拟OrdenTrabajo OrdenesTrabajo{get;set;}
公共虚拟ICollection AccionesDocumentos{get;set;}
}
我可以在ViewModel中为Accion的每个属性创建一个属性,但是是否有任何方法可以接收更改而不必为Accion的每个属性创建属性?您有两种选择—修改Accion类以实现INotifyPropertyChanged,或者创建ViewModel包装器来实现它 你把它放在哪里取决于你——做对你最有用的事情。有
您可以通过查看以下内容来手动执行此操作-尝试使用Google查找INotifyPropertyChanged面向方面编程。存在堆栈溢出。ViewModel的这种冗余双重包装是经典MVVM中的常见问题,也让我发疯 您有几个选择:
INotifyPropertyChanged
,并以使用AccionActual
属性的方式向视图公开实体无论哪种方式,@user1001552都必须为每个成员引发属性更改事件,为此,他/她必须为类Accion的每个成员实现一个属性
public partial class Accion : Entity
{
public Accion()
{
this.AccionesDocumentos = new HashSet<AccionDocumento>();
}
public int IdAccion { get; set; }
public int IdEmpleado { get; set; }
public string Descripcion { get; set; }
public string DescripcionDetalle { get; set; }
public bool Finalizada { get; set; }
public Nullable<int> IdExpediente { get; set; }
public Nullable<int> IdOrdenTrabajo { get; set; }
public bool Facturable { get; set; }
public Nullable<short> GestComAlbaranAño { get; set; }
public Nullable<short> GestComAlbaranEmpresa { get; set; }
public Nullable<int> GestComAlbaranNumero { get; set; }
public bool Facturado { get; set; }
public bool ComputarHorasACliente { get; set; }
public string DescripcionInterna { get; set; }
public virtual Aplicacion Aplicacione { get; set; }
public virtual AplicacionModulo AplicacionesModulo { get; set; }
public virtual Cliente Cliente { get; set; }
public virtual ClienteContacto ClientesContacto { get; set; }
public virtual Empleado Empleado { get; set; }
public virtual Expediente Expediente { get; set; }
public virtual OrdenTrabajo OrdenesTrabajo { get; set; }
public virtual ICollection<AccionDocumento> AccionesDocumentos { get; set; }
}