简体   繁体   English

C#中的子女父母财产变更

[英]Child Parent Property Change in C#

I have a property in a class (eg ParentClass ) in C# that is binding with ObservableCollection of another class Type (eg ChildClass ). 我在C#的一个类(例如ParentClass )中有一个属性,该属性与另一个类Type(例如ChildClass )的ObservableCollection绑定。 My question is how to change the value of ChildClass property by using the ParentClass property such that RaisePropertyChanged("ParentProperty") should get triggered? 我的问题是如何通过使用ParentClass属性更改ChildClass属性的值,以使RaisePropertyChanged("ParentProperty")应该被触发?

I use this coding: 我使用以下编码:

foreach (var pIn in ParentProperty.Where(ms => ms.Name == onNameUpdateObj.Name && ms.UnRead == true))
{
    if (pIn != null)
    {
         pIn.UnRead = false;
    }
}

ParentProperty is the property binding with ObservableCollection<ChildClass> and ChildClass contains the property UnRead . ParentProperty是与ObservableCollection<ChildClass>绑定的属性, ChildClass包含属性UnRead When I change the value of UnRead RaisePropertyChanged("ParentProperty") returns null . 当我更改UnRead RaisePropertyChanged("ParentProperty")的值时,将返回null I want RaisePropertyChanged("ParentProperty") to be triggered whenever I change the property value of pIn.UnRead . 每当我更改pIn.UnRead的属性值时,我都想RaisePropertyChanged("ParentProperty")

ObservableCollection<T> does not provide notifications for when one or more properties of the collection it maintains change, it only provides notifications for when items get added, removed, or when the whole list is refreshed . ObservableCollection<T>不提供有关它维护的集合的一个或多个properties何时发生更改的通知,它仅提供有关when items get added, removed, or when the whole list is refreshed通知。

If you want to know when a property in your collection changes, you need to implement a notification for that yourself. 如果您想知道集合中的property何时更改,则需要自己实现一个通知。 Such a mechanism can be implemented with the aid of INotifyPropertyChanged and/or EventHandler . 可以借助INotifyPropertyChanged和/或EventHandler来实现这种机制。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM