Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/295.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
C# 更改属性的父引用后刷新属性的绑定_C#_.net_Wpf_Binding - Fatal编程技术网

C# 更改属性的父引用后刷新属性的绑定

C# 更改属性的父引用后刷新属性的绑定,c#,.net,wpf,binding,C#,.net,Wpf,Binding,假设我有一个ViewModel,其上有一个名为Customer的属性。当客户更改时,它会引发NotifyPropertyChanged Customer类上有其他属性,所有这些属性都在setter中更改。例如,它有FirstName和LastName字符串。其中的另一个属性称为Address 地址具有诸如Line1、Line2、Zip、State等属性。它们在更改时都会引发NotifyPropertyChanged 我将UI元素直接绑定到这些元素。我发现当我这样做的时候: CurrentCust

假设我有一个ViewModel,其上有一个名为Customer的属性。当客户更改时,它会引发NotifyPropertyChanged

Customer类上有其他属性,所有这些属性都在setter中更改。例如,它有FirstName和LastName字符串。其中的另一个属性称为Address

地址具有诸如Line1、Line2、Zip、State等属性。它们在更改时都会引发NotifyPropertyChanged

我将UI元素直接绑定到这些元素。我发现当我这样做的时候:

CurrentCustomer = FoundCustomer;
CurrentAddress = FoundCustomer.Address;
我的BoundControls中的FirstName和LastName等项正在更新,但Line1、Line2、Zip和State没有更新

我已经尝试过制作Address的ViewModel实例,如下所示:

CurrentCustomer = FoundCustomer;
CurrentAddress = FoundCustomer.Address;
当我这样做时,绑定属性会正确更新

关于装订,我有什么遗漏吗?它是否只更新一级深度?还是只值不引用对象


或者这是否有效,我需要仔细查看我的绑定?

尝试在setter中提升NotifyPropertyChanged,而不是在需要提升时在代码中的某个位置提升属性。

尝试在setter中提升NotifyPropertyChanged,仅当需要提升属性时,才尝试在代码中的某个位置提升属性。

CurrentCustomer如何绑定到表单?CurrentCustomer如何绑定到表单?