I have a GridView
with some columns displaying materials. The viewmodel values are all saved in kg, for some of the the view should convert and display them as liters. Which is easily done the one way using a IMultiValueConverter
.
public object Convert(object[] values, ...){
var valueInKg = (double)values[0];
var density = (double)values[1];
return valueInKg/density;
}
Now I have problems doing the backward conversion. I have tried to store the input values (density) in the converter, but do have a single instance of it and thus wrong density values sometimes. I found this x:shared="false" approach, but want to set the converter in a class derived from System.Windows.Data.MultiBinding
.
public class MyBinding : MultiBinding {
public MyBinding(){
Converter = new MyConverter();
}
}
I assumed this will result in a separate instance for each Binding - it does not. How can I achieve that?
EDIT:
As suggested by mm8 in this answer the problem lies in the binding instance. When defining the binding on a GridViewColumn
in its cell template I will hit the constructor only once per column. So the question is how can I change that - is it even possible?