Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
MVVM子属性更改检测_Mvvm_Entity - Fatal编程技术网

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

我的问题如下:

我正在使用MVVM模式,我想知道如何检测子属性的更改

我有一个文本框:

<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
    属性的方式向视图公开实体
  • 将实体完全隐藏在相应的ViewModel对象后面,并仅向视图中实际需要的ViewModel添加那些属性。引入一个聪明的更改通知基础结构,它将模型中的更改通知给您的ViewModel,并相应地提高ViewModel中的PropertyChanged。此“更改通知基础结构”可能是一个事件,您可能可以通过某种批量/元更新(例如,当您收到“实体已更改”事件时,为ViewModel中的所有相关属性引发NotifyPropertyChanged)

  • 无论哪种方式,@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; }
    
    
        }