让我们首先想象一下域对象:
Customer:
Name
Phone
List of Orders
Order:
Date
Amount
然后使用以下字段集设置我的网格:
<XamDataGrid>
<XamDataGrid.FieldLayouts>
<FieldLayout Key="Customers">
<Field Name="Orders" IsExpandable="True" />
<Field Name="Name" />
<Field Name="Phone" />
</FieldLayout>
<FieldLayout ParentFieldLayoutKey="Customers">
<Field Name="Date" />
<Field Name="Amount" />
</FieldLayout>
</XamDataGrid.FieldLayouts>
</XamDataGrid>
当我的客户列表预先填充了数据时,这可以正常工作。每个客户行都获得一个+,当单击时,该行会展开以显示订单列表。
现在,所有好事都要结束......
我们尝试获取订单异步,这在用户展开行时为我们提供了一个空集合。当异步调用完成时,集合会更新,但网格不会更新。
由于集合最初为空,因此网格会删除+,并且用户不再具有折叠/展开的能力。如果集合在用户首次展开行时包含数据,那么如果我们向集合中添加更多对象,则网格需要更新。
这应该如何运作?
答案 0 :(得分:3)
尝试使用ObservableCollection作为树结构中的节点集合。
答案 1 :(得分:0)
请尝试这个..它有效
首先,创建两个这样的类
public class CustomerDetails1
{
public string Id { set; get; }
public string Name { set; get; }
public string Place { set; get; }
public string Mobile { set; get; }
public List<Level2Customer> Level2CustomerInst { get; set; }
}
public class Level2Customer
{
public string Address { set; get; }
public string Street { set; get; }
}
在Xaml页面
<igWPF:XamDataGrid Width="767" Name ="TestDatagrid" DataSource="{Binding CustomerList1}" Height="403">
<igWPF:XamDataGrid.FieldLayoutSettings>
<igWPF:FieldLayoutSettings AutoGenerateFields="False"/>
</igWPF:XamDataGrid.FieldLayoutSettings>
<igWPF:XamDataGrid.ViewSettings>
<igWPF:GridViewSettings UseNestedPanels="True" Orientation="Vertical"/>
</igWPF:XamDataGrid.ViewSettings>
<igWPF:XamDataGrid.FieldLayouts>
<igWPF:FieldLayout Key="layer1">
<igWPF:FieldLayout.Fields>
<igWPF:Field Name="Id" Visibility="Visible"/>
<igWPF:Field Name="Name" Visibility="Visible"/>
<igWPF:Field Name="Place" Visibility="Visible"/>
<igWPF:Field Name="Mobile" Visibility="Visible"/>
<igWPF:Field Name="Level2CustomerInst" Visibility="Visible" IsExpandable="True" Label="Level2CustomerInst" IsSelected="True" IsPrimary="True" />
</igWPF:FieldLayout.Fields>
</igWPF:FieldLayout>
<igWPF:FieldLayout Key="Level2CustomerInst" ParentFieldName="Level2CustomerInst" ParentFieldLayoutKey="layer1">
<igWPF:FieldLayout.Fields>
<igWPF:Field Name="Address" Label="Address"/>
<igWPF:Field Name="Street" Label="Street"/>
</igWPF:FieldLayout.Fields>
</igWPF:FieldLayout>
</igWPF:XamDataGrid.FieldLayouts>
</igWPF:XamDataGrid>
如果要在加载时展开子列表,可以尝试处理InitializeRecord事件并设置Record的IsExpanded属性:
private void TestDatagrid_OnInitializeRecord(object sender, InitializeRecordEventArgs e)
{
e.Record.IsExpanded = true;
}