Reputation:
I am working on converter, I am very new. I don't know, how to get the value from xaml binding. May be will write my code.
In my convertback code I am bit confused. For Double B, I need the value of B inXAML
<TextBlock Text="Offset X [px]"
Style="{StaticResource StdTextBlockStyle}" />
<TextBox x:Uid="TextBox_1"
Style="{StaticResource StdTextBoxStyle}" >
<TextBox.Text>
<MultiBinding Converter="{StaticResource Conv}">
<Binding Path="B" />
<Binding Path="A" />
</MultiBinding>
</TextBox.Text>
</TextBox>
<TextBlock />
//C# Code //
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
double B = (double)values[0];
double A = (double)values[1];
double C = A-B;
return C;
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
double C = (double)value;
double B = // I DON'T KNOW HOW TO GET VALUE FOR B. B is from XAML// ???
object[] ret = new object[1];
ret[0] = C + B;
return ret;
Upvotes: 0
Views: 700
Reputation: 3797
You should understand, that result in ConvertBack
it is combination of
double B = (double)values[0];
double A = (double)values[1];
you defined in Convert
.
The main idea of Conversion in MultiValueConverter
is definition of your own logic how do you want to see these values. That means you need to define your logic to calculate this array.
According to your Convert
function:
double C = A-B;
We have in ConvertBack
:
double B=A-C;
double A=C+B;
We cannot calculate A and B to define
Array[] x = new []{ A, B };
Because we have here equalation with 2 unknown variables. Sorry, I don't believe this expression is convertible back.
Upvotes: 1