I have class deriving from TextBox to which I attach a dependency property of type point called position and in its set section I set the Canvas.Top and Canvas.Left property. Just to clarify, whenever the source property changes it calls the set section of the property correct? Because when my source updates the canvastop and canvasleft properties of the textbox don’t get updated.
Any help would be appreciated.
public static readonly DependencyProperty PositionProperty = DependencyProperty.Register("Position", typeof(Point), typeof(TextBox), new FrameworkPropertyMetadata(new Point(0, 0)));
public Point Position
{
get { return (Point)GetValue(PositionProperty); }
set
{
SetValue(PositionProperty, value);
Canvas.SetLeft(this, value.X - this.Width / 2);
Canvas.SetTop(this, value.Y - this.FontSize);
}
}
this.TextBoxShape.SetBinding(TextBoxShape.PositionProperty, CreateConnectorBinding(this));
Where CreateConnectorBinding returns the mid point of an ellipse based on it Canvas.Top and Canvas.Left properties. But when the Ellipse’s Canvas.Top and Canvas. Left properties get updated the position of the textbox is still not updated.
When the PositionProperty value changes via the binding, it does not use the setter. You need to add a PropertyChangeCallback to the FrameworkPropertyMetadata on your DependencyProperty registration: