The problem:
I am using MultiBinding
with converter to pass (x,y)
coordinates into method.
And I can't make it working in back direction:
public class MyConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
var x = (int)values[0];
var y = (int)values[1];
return Model.Get(x, y);
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
Model.Set(x, y, value); // how to get x, y here?
return new object[] { Binding.DoNothing, Binding.DoNothing };
}
}
Additional info:
The data will be visualized in a form of table. Here is cell template:
<TextBox>
<TextBox.Text>
<MultiBinding Converter="{StaticResource converter}" Mode="TwoWay">
<Binding Path="X" Mode="OneWay" />
<Binding Path="Y" Mode="OneWay" RelativeSource="..." />
</MultiBinding>
</TextBox.Text>
</TextBox>
The idea is to use converter, which receive x
(from cell view model) and y
(from parent column view model, notice RelativeSource
) and calls Get(x,y)
to display value.
However, when user entered something, ConvertBack
is called and I need to call Set(x, y, value)
method.
How do I pass x
and y
into ConvertBack
?