Access to bound data in IMultiValueConverter.ConvertBack() in C#/WPF

Posted by absence on Stack Overflow See other posts from Stack Overflow or by absence
Published on 2010-04-17T00:11:16Z Indexed on 2010/04/17 0:13 UTC
Read the original article Hit count: 1277

Filed under:
|
|
|

I have a problem with a multibinding:

<Canvas>
 <local:SPoint x:Name="sp" Width="10" Height="10">
  <Canvas.Left><!-- irrelevant binding here --></Canvas.Left>
  <Canvas.Top>
   <MultiBinding Converter="{StaticResource myConverter}" Mode="TwoWay">
    <Binding ElementName="cp1" Path="(Canvas.Top)"/>
    <Binding ElementName="cp1" Path="Height"/>
    <Binding ElementName="cp2" Path="(Canvas.Top)"/>
    <Binding ElementName="cp2" Path="Height"/>
    <Binding ElementName="sp" Path="Height"/>
    <Binding ElementName="sp" Path="Slope" Mode="TwoWay"/>
   </MultiBinding>
  </Canvas.Top>
 </local:SPoint>
 <local:CPoint x:Name="cp1" Width="10" Height="10" Canvas.Left="20" Canvas.Top="150"/>
 <local:CPoint x:Name="cp2" Width="10" Height="10" Canvas.Left="100" Canvas.Top="20"/>
</Canvas>

In order to calculate the Canvas.Top value, myConverter needs all the bound values. This works great in Convert(). Going the other way, myConverter should ideally calculate the Slope value (Binding.DoNothing for the rest), but it needs the other values in addition to the Canvas.Top one passed to ConvertBack(). What is the right way to solve this?

I have tried making the binding OneWay and create an additional multibinding for local:SPoint.Slope, but that causes infinite recursion and stack overflow. I was thinking the ConverterParameter could be used, but it seems like it's not possible to bind to it.

© Stack Overflow or respective owner

Related posts about c#

Related posts about wpf