2012-10-10 51 views
0

我想將MyCustomers綁定到TreeListControl TreeListColumn FieldName =「Id」Binding =「如何綁定CustomerId」我該怎麼做?如何在DevExpression TreeListColumn上綁定ViewModel?

<dxg:TreeListControl Name="MyControl" ItemsSource="{Binding Path=MyCustomers}" 
    Height="296" Width="750" Grid.Row="1" Grid.Column="0" HorizontalAlignment="Left"> 
    <dxg:TreeListControl.Columns> 
     <dxg:TreeListColumn FieldName="Id" Binding="How to Bind CustomerID ?????" /> 
     <dxg:TreeListColumn FieldName="CustomerGroup" Binding="How to Bind CustomerGroup ?????" /> 
    </dxg:TreeListControl.Columns> 
    <dxg:TreeListControl.View> 
     <dxg:TreeListView AutoWidth="True" KeyFieldName="Id" ParentFieldName="ParentId" NavigationStyle="Row" /> 
    </dxg:TreeListControl.View> 
</dxg:TreeListControl> 

視圖模型:

public class CustomerViewModel : BaseViewModel 
{ 
    public IList<Model.App.Customer> MyCustomers 
    { 
     get; 
     private set; 
    } 

    public CustomerViewModel() 
    { 
     CustomerDetail = new CustomerDetail(); 
     this.MyCustomers = CustomerRespiratory.SelectMyCustomers(); 
    } 
} 

型號:

public class Customer 
{ 
    public int CustomerID { get; set;} 
    public int CustomerGroup { get; set;} 
} 
+2

你嘗試過什麼乍一看我說綁定=「{結合客戶ID}」可能是你所需要的 – michele

回答

1

您應該只指定CustomerID作爲重點領域和CustomerGroup作爲父字段。這是很清楚的"Binding to Self-Referential Data Structure"文章描述:

<dxg:TreeListControl ItemsSource="{Binding Path=MyCustomers}"> 
    <dxg:TreeListControl.Columns> 
     <dxg:TreeListColumn FieldName="CustomerId"/> 
     <dxg:TreeListColumn FieldName="CustomerGroup"/> 
    </dxg:TreeListControl.Columns> 
    <dxg:TreeListControl.View> 
     <dxg:TreeListView KeyFieldName="CustomerId" ParentFieldName="CustomerGroup" 
       AutoWidth="True" NavigationStyle="Row" /> 
    </dxg:TreeListControl.View> 
</dxg:TreeListControl> 

你可以閱讀更多的文章"TreeListView Data Binding"

參見:
DXTreeList Getting Started - Lesson 1 - Binding to Data