Data binding between two dependency properties

I am trying to do data binding between two dependency properties. I think this should be pretty easy, anyway I just don't get it. I have googled already but I couldn't figure out what I was doing wrong.

I am trying to bind the ControlPointProperty to the QuadraticBezierSegment.Point1Property class, however it doesn't work. Thanks for any hint!

 class DataBindingTest : DependencyObject
{
    // Dependency Property
    public static readonly DependencyProperty ControlPointProperty;


    // .NET wrapper
    public Point ControlPoint
    {
        get { return (Point)GetValue(DataBindingTest.ControlPointProperty); }
        set { SetValue(DataBindingTest.ControlPointProperty, value); }
    }


    // Register Dependency Property
    static DataBindingTest()
    {
        DataBindingTest.ControlPointProperty = DependencyProperty.Register("ControlPoint", typeof(Point), typeof(DataBindingTest));
    }


    public DataBindingTest()
    {
        QuadraticBezierSegment bezier = new QuadraticBezierSegment();

        // Binding
        Binding myBinding = new Binding();
        myBinding.Source = ControlPointProperty;
        BindingOperations.SetBinding(bezier, QuadraticBezierSegment.Point1Property, myBinding);

        // Test Binding: Change the binding source
        ControlPoint = new Point(1, 1);


        MessageBox.Show(bezier.Point1.ToString()); // gives (0,0), should be (1,1)
    }
}

      

+2


source to share


1 answer


The source is not a bind property, but the source. It works:



Binding myBinding = new Binding("ControlPoint");
myBinding.Source = this;

      

+1


source







All Articles