I have the following working XAML code that basically binds a couple of properties to calculate the final position of my user control:
<UserControl x:Class="CurvePointControl"
....
>
<UserControl.Resources>
<local:VToYConverter x:Key="vToYConverter" />
</UserControl.Resources>
<UserControl.RenderTransform>
<TranslateTransform x:Name="XTranslateTransform" >
<TranslateTransform.Y>
<MultiBinding Converter="{StaticResource vToYConverter}">
<Binding ElementName="curveEditPoint" Path="V"/>
<Binding RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type local:CurveEditor}}" Path="MinV"/>
<Binding RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type local:CurveEditor}}" Path="MaxV"/>
<Binding RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type local:CurveEditor}}" Path="ActualHeight"/>
</MultiBinding>
</TranslateTransform.Y>
</TranslateTransform>
</UserControl.RenderTransform>
…
For various reasons (but esp to avoid the relative source, I am now trying to do the same in code behind without success.
This is my current code:
public CurvePointControl(CurveEditor CV)
{
InitializeComponent();
MultiBinding multiBinding = new MultiBinding();
multiBinding.Converter = m_VToYConverter;
multiBinding.Bindings.Add(new Binding("V"));
multiBinding.Bindings.Add(new Binding(CV.MinVProperty)); // doesn't work
multiBinding.Bindings.Add(new Binding(CV.MaxVProperty)); // doesn't work
multiBinding.Bindings.Add(new Binding(CV.ActualHeight)); // doesn't work
multiBinding.NotifyOnSourceUpdated= true;
this.SetBinding(TranslateTransform.YProperty, multiBinding);
//Doesn't work too:
//BindingOperations.SetBinding(XTranslateTransform, TranslateTransform.YProperty, multiBinding);
}
I still can’t believe that it is so hard to convert the XAML into c# code. The converter is called but only once and without valid property values.
Any idea of what’s wrong?
How could I debug such a problem?
You need sources: