2011-08-03 85 views
0

我在這個數據網格列WPF綁定DataGridComboBoxColumn從代碼

 <DataGrid.Columns> 
      <DataGridComboBoxColumn SelectedItemBinding="{Binding Path=ProductId}" DisplayMemberPath="Name" SelectedValuePath="Id" />   
      <DataGridTextColumn Binding="{Binding Path=StorageAmount}" Width="*" Header="Со склада" /> 
      <DataGridTextColumn Binding="{Binding Path=Trade1Amount}" Width="*" Header="С точки 1" /> 
      <DataGridTextColumn Binding="{Binding Path=Trade2Amount}" Width="*" Header="С точки 2" /> 
      <DataGridTextColumn Binding="{Binding Path=TotalAmount}" Width="*" Header="Всего" FontWeight="Bold" /> 
     </DataGrid.Columns> 

我如何可以綁定DataGridComboBoxColumn編程方式從代碼,而不是從XAML?我不能定義名稱DataGridComboBoxColumn所以我不能爲了填補這一組合框

回答

1

使用X的的DataContext從代碼中訪問: - 命名與Name屬性。這將做你正在尋找的東西:

<DataGridComboBoxColumn x:Name="m_yourComboBoxColumn" SelectedItemBinding="{Binding Path=ProductId}" DisplayMemberPath="Name" SelectedValuePath="Id" />    
相關問題