【问题标题】:Silverlight: Bind to all items in nested listsSilverlight:绑定到嵌套列表中的所有项目
【发布时间】:2010-02-05 23:12:21
【问题描述】:

我正在使用具有 RIA 服务的 Silverlight 3。我有一个名为“source”的简单 RIA DomainDataSource,其中绑定了几个 ListBox。源查询的方法返回一个简单的对象图:父母的集合,其中每个父母都有一个孩子的集合。

我的 UI 有两个列表框。 ParentListBox 将 ItemsSource 绑定到 {Binding Data, ElementName=source}",DisplayMemberPath 为 Name。这显示了所有父母的姓名,这是我想要的。

ChildrenListBox 将 ItemsSource 绑定到 {Binding Data.Children, ElementName=source}。结果是 ChildrenListBox 显示了 ParentListBox 中当前选择的父项的所有子项:当我更改选择时,ChildrenListBox 中的值会发生变化。我猜这是非常聪明的行为,但不是我想要的。我想要的是让第二个 ListBox 始终显示 all 的父母的 all 的孩子,而不管在 ParentListBox 中选择了什么。我怎样才能做到这一点?

【问题讨论】:

    标签: silverlight collections binding


    【解决方案1】:

    使用您选择的 IEnumerable 在您的视图模型上创建一个 ChildrenList 属性。 将 ChildrenListBox ItemsSource 属性绑定到 ChildrenList。 在您的 Web 回调中,使用从 RIA 服务返回的父级填充 ChildrenList 属性的基础集合。

    foreach(var parent in ParentList)
    {
        foreach(var child in parent.Children)
        {
            _childrenList.Add(child)
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2016-05-23
      • 2020-05-04
      • 1970-01-01
      • 2011-09-03
      • 1970-01-01
      • 1970-01-01
      • 2013-04-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多