C# 如何让CSLA 3.02 BusinessListBase ListChanged事件识别OnPropertyChanged触发事件的子对象?

C# 如何让CSLA 3.02 BusinessListBase ListChanged事件识别OnPropertyChanged触发事件的子对象?,c#,winforms,parent-child,inotifypropertychanged,csla,C#,Winforms,Parent Child,Inotifypropertychanged,Csla,我有一个使用CSLA 3.0.2的项目 我有一个BusinessListBase集合对象,它的子项具有IsDefault属性 当一个子对象的IsDefault属性设置为true时,我想将其他子成员IsDefault属性设置为false 我正在调用子setter中的OnPropertyChanged(“IsDefault”),并引发collections ListChanged事件。但是,事件的发送方是集合对象,而不是引发事件的子对象。ListChangedEventArgs(e)中的子项也不存在

我有一个使用CSLA 3.0.2的项目

我有一个BusinessListBase集合对象,它的子项具有IsDefault属性

当一个子对象的IsDefault属性设置为true时,我想将其他子成员IsDefault属性设置为false

我正在调用子setter中的OnPropertyChanged(“IsDefault”),并引发collections ListChanged事件。但是,事件的发送方是集合对象,而不是引发事件的子对象。ListChangedEventArgs(e)中的子项也不存在

如何获取对引发事件的特定子实例的引用

或者我应该用别的方法来做?比如在子setter中获取对父对象的引用并在那里执行


感谢您的帮助

我从CSLA 3.6开始,但我认为这将在CSLA 3中起作用:

您应该发现在BusinessListBase集合类中有一个OnChildChanged方法可以重写。该方法有一个参数Csla.Core.ChildChangedEventArgs,其中包含对已更改的子对象的引用,以及该对象的哪个属性已更改

然后,可以在该方法中循环集合中的其他子级,将它们设置为IsDefault=false

protected override void OnChildChanged(Csla.Core.ChildChangedEventArgs e)
{
    base.OnChildChanged(e);

    switch (e.PropertyChangedArgs.PropertyName)
    {
        case "IsDefault":

            if ( ((ChildObjectType)e.ChildObject).IsDefault == true )
            {
                // then loop all the other childern 
                foreach (ChildObjectType child in this)
                {
                    if (child != e.ChildObject && child.IsDefault == true)
                    {
                        child.IsDefault = false; 
                    }
                }
            }
            break;
    }

}

如果这不起作用,那么另一种方法是使用子对象中的Parent属性获取对集合的引用,然后调用您在BLB集合中编写的更新其他子对象的方法。根据类的设置方式,您可能需要查看父级的父级

我从CSLA 3.6开始,但我认为这将在CSLA 3中起作用:

您应该发现在BusinessListBase集合类中有一个OnChildChanged方法可以重写。该方法有一个参数Csla.Core.ChildChangedEventArgs,其中包含对已更改的子对象的引用,以及该对象的哪个属性已更改

然后,可以在该方法中循环集合中的其他子级,将它们设置为IsDefault=false

protected override void OnChildChanged(Csla.Core.ChildChangedEventArgs e)
{
    base.OnChildChanged(e);

    switch (e.PropertyChangedArgs.PropertyName)
    {
        case "IsDefault":

            if ( ((ChildObjectType)e.ChildObject).IsDefault == true )
            {
                // then loop all the other childern 
                foreach (ChildObjectType child in this)
                {
                    if (child != e.ChildObject && child.IsDefault == true)
                    {
                        child.IsDefault = false; 
                    }
                }
            }
            break;
    }

}
如果这不起作用,那么另一种方法是使用子对象中的Parent属性获取对集合的引用,然后调用您在BLB集合中编写的更新其他子对象的方法。根据类的设置方式,您可能需要查看父级的父级