I have a dataset which i bind to datagrid from wpf toolkit(forced 开发者_如何转开发to use .net 3.5).. I was ignorant as newbie to WPF and C# and didnt bind a collection of my objects,that would help a lot and would solve my problem!
So the cell is something like that
<my:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Length}" />
</DataTemplate>
</my:DataGridTemplateColumn.CellTemplate>
I would like to do something like
<my:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Length}" />
<TextBlock Text="{Binding ????????}" />
</DataTemplate>
</my:DataGridTemplateColumn.CellTemplate>
Where ????? i would like to bind a value that depends from 2 values from the dataset and about 1000 other not in dataset... If i could bind to a method and provide these 2 as parameter .
The only solution i can think is adding 3 extra collumns to dataset .Then iterate each row and set the new's collumn cell with the calculated value.
Why don't you just adjust your code to bind to a collection, as you just say that this wil solve it
Forget my last answer.
Create a new collection just for that particular cell. Something like:
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);
}
}
You can add an event handler which calls calculation everytime the values in X and Y change. Finally bind foo to the cell
精彩评论