【问题标题】:How do you get CSLA 3.02 BusinessListBase ListChanged event to identify the child object whose OnPropertyChanged triggered the event?您如何获取 CSLA 3.02 BusinessListBase ListChanged 事件来识别其 OnPropertyChanged 触发事件的子对象?
【发布时间】:2013-12-04 21:33:01
【问题描述】:

我有一个使用 CSLA 3.0.2 的项目。

我有一个 BusinessListBase 集合对象,其中包含具有 IsDefault 属性的子项。

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

我在子设置器中调用 OnPropertyChanged("IsDefault") 并且我有它引发集合 ListChanged 事件。但是,事件的发送者是 Collection 对象,而不是引发事件的子对象。 ListChangedEventArgs (e) 中的子项也不是。

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

或者我应该以其他方式这样做吗?喜欢在子设置器中获取对父级的引用并在那里执行吗?

感谢任何帮助。

【问题讨论】:

    标签: c# winforms parent-child inotifypropertychanged csla


    【解决方案1】:

    我从 3.6 开始使用 CSLA,但我认为这将适用于 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 集合中编写的方法来更新其他子项。根据您的课程设置方式,您可能需要查看 Parent's Parent。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-12-28
      • 1970-01-01
      • 1970-01-01
      • 2010-11-23
      • 1970-01-01
      • 2012-04-07
      • 2013-02-03
      • 2017-01-21
      相关资源
      最近更新 更多