2011-03-30 36 views
2

讓我們先想象一些領域對象:Infragistics xamDataGrid綁定到分層數據 - 如何通知網格在第二級更改?

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> 

,當我的客戶名單是預先填充數據也能正常工作。每個客戶行都獲得一個+,點擊後,該行將展開以顯示訂單列表。

現在,一切美好的東西玩完了......

我們試圖讓訂單異步,當用戶展開行這給了我們一個空的集合。當異步調用完成時,集合被更新,但網格不會更新。

由於集合最初是空的,網格刪除了+,並且用戶不再具有拼湊/展開的能力。如果集合包含數據,當用戶第一次展開該行時,如果向集合添加更多對象,則網格要更新。

這應該如何工作?

回答

3

嘗試使用ObservableCollection作爲樹形結構中的節點集合。

+0

哇。那容易?現在唯一的問題是,更改發生在後臺線程中,所以我們需要找到一種方法來使ui線程上的可觀察收集信號發生變化。謝謝! – Vegar 2011-03-30 21:16:40

0

請嘗試this..It工作

首先,這樣

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事件並設置記錄的IsExpanded屬性:

private void TestDatagrid_OnInitializeRecord(object sender, InitializeRecordEventArgs e) 
    { 
     e.Record.IsExpanded = true; 
    } 
相關問題