Wpf 绑定到代码隐藏中的附加属性

Wpf 绑定到代码隐藏中的附加属性,wpf,binding,properties,Wpf,Binding,Properties,如何在代码隐藏中实现以下xaml绑定 <Canvas x:Name="_YAxis"> <Label Content="0.2" Canvas.Left="25" Canvas.Bottom="{Binding ElementName=_YAxis, Path=ActualHeight, Converter={StaticResource myPercentageOf}, ConverterParameter={StaticResource Constant_pt2}

如何在代码隐藏中实现以下xaml绑定

<Canvas x:Name="_YAxis">
    <Label Content="0.2" Canvas.Left="25" Canvas.Bottom="{Binding ElementName=_YAxis, Path=ActualHeight, Converter={StaticResource myPercentageOf}, ConverterParameter={StaticResource Constant_pt2} }"  />
</Canvas>
但是如何将绑定附加到画布。左附加属性?

给您:

    Binding b = new Binding();
    b.Path = new PropertyPath("ActualHeight");
    b.Source = _YAxis;// OR b.ElementName = "_YAxis"
    b.Converter = Resources["myPercentageOf"];
    b.ConverterParameter = Resources["Constant_pt2"];

    Label label = new Label() { label.Content = "0.2" };
    _YAxis.Children.Add(label);
    label.SetBinding(Canvas.BottomProperty, b); //Binding Canvas.Bottom to ActualHeight of _YAxis
    Canvas.SetLeft(label, 25); //Setting Canvas.Left

我没有感谢你的回应,我为我的粗鲁道歉。我不知道如何获取更新通知,因此没有看到您的响应。
    Binding b = new Binding();
    b.Path = new PropertyPath("ActualHeight");
    b.Source = _YAxis;// OR b.ElementName = "_YAxis"
    b.Converter = Resources["myPercentageOf"];
    b.ConverterParameter = Resources["Constant_pt2"];

    Label label = new Label() { label.Content = "0.2" };
    _YAxis.Children.Add(label);
    label.SetBinding(Canvas.BottomProperty, b); //Binding Canvas.Bottom to ActualHeight of _YAxis
    Canvas.SetLeft(label, 25); //Setting Canvas.Left