Databinding between 2 Dependency Properties
Posted
by stefan.at.wpf
on Stack Overflow
See other posts from Stack Overflow
or by stefan.at.wpf
Published on 2010-04-11T20:55:27Z
Indexed on
2010/04/11
21:03 UTC
Read the original article
Hit count: 489
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)
}
}
© Stack Overflow or respective owner