I have the following working XAML code that basically binds a couple of properties to calculate the end 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 a relative source, I am now trying to do the same in code 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));
multiBinding.Bindings.Add(new Binding(CV.MaxVProperty));
multiBinding.Bindings.Add(new Binding(CV.ActualHeight));
multiBinding.NotifyOnSourceUpdated= true;
this.SetBinding(TranslateTransform.YProperty, multiBinding);
}
I still can't believe it is so hard to convert XAML to C # code. The converter is invoked, but only once and without valid property values.
Any idea what is wrong? How could I debug such a problem?
source
share