2010-10-16 54 views
0

我有一個數據集,它可以從wpf工具包綁定到datagrid(被強制使用.net 3.5).. 我對WPF和C#的新手無知,並且沒有綁定我的集合對象,這將有助於很多,並會解決我的問題!將計算值以某種方式綁定到數據網格

所以細胞是類似的東西

<my:DataGridTemplateColumn.CellTemplate> 
    <DataTemplate> 
     <TextBlock Text="{Binding Length}" /> 
    </DataTemplate> 
</my:DataGridTemplateColumn.CellTemplate> 

我想這樣做

 <my:DataGridTemplateColumn.CellTemplate> 
     <DataTemplate> 
      <TextBlock Text="{Binding Length}" /> 
<TextBlock Text="{Binding ????????}" /> 
     </DataTemplate> 
    </my:DataGridTemplateColumn.CellTemplate> 

哪裏?????我想綁定一個值,該值取決於數據集中的2個值和大約1000個不在數據集中的值... 如果我可以綁定到方法並提供這2個參數。

我能想到的唯一解決方案是將3個額外的列添加到數據集中。然後迭代每行並將新的列表單元格與計算值一起設置。

回答

0

你爲什麼不只是調整你的代碼 綁定到一個集合,就像你剛纔說的 這西港島線解決它

忘了我最後的答案。

爲該特定單元創建一個新的集合。例如:

public Observablecollection<int> foo = new ObservableCollection<int>() 


private void Calculation(int[] X, int[] Y) 
{ 
    foo.Clear(); 
    int i; 
    for(int index = 0; index < X.Length; index++) 
    { 
     //Calculation Like 
     i = X[index] + y[index]; 
     foo.Add(i); 
    } 
} 

您可以添加一個事件處理程序,該程序會在每次X和Y中的值發生更改時調用計算。 最後將foo綁定到單元格

+0

因爲如果我這樣做,我將不得不更改許多部分的代碼....並且應該寫入新的方法.. – GorillaApe 2010-10-16 16:07:55