views:

30

answers:

1

Hello, I'm trying to do databinding between 2 Dependency Properties. I guess this should be quite easy, anyways I just don't get it. I already googled but I couldn't really find out what I'm doing wrong.

I'm trying to bind the ControlPointProperty to the QuadraticBezierSegment.Point1Property, 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)
    }
}
+1  A: 

Source is not a property to bind, but source object. This works:

Binding myBinding = new Binding("ControlPoint");
myBinding.Source = this;
majocha
thank you so much for the fast reply. works not without any problems. for setting the path one can use myBinding.Path = new PropertyPath(ControlPointProperty);which has better IDE integration / no string as parameter.
stefan.at.wpf