I have 2 StackPanel, which can be move around inside a canvas. and I want the line to re-drawn when I drag one of the StackPanel. How do I properly bind the line points(X1,Y1,X2,Y2) between the two StackPanel? This is how I did right now :
Line line = new Line();
line.Stroke = new SolidColorBrush(Colors.Black);
line.StrokeThickness = 1.5;
Binding ogX = new Binding();
ogX.Source = originalStackPanel.TransformToAncestor(qbw).Transform(new Point(0, 0)).X;
Binding ogY = new Binding();
ogY.Source = originaStackPanel.TransformToAncestor(qbw).Transform(new Point(0, 0)).Y;
Binding tgX = new Binding();
tgX.Source = targetStackPanel.TransformToAncestor(qbw).Transform(new Point(0, 0)).X;
Binding tgY = new Binding();
tgY.Source = targetStackPanel.TransformToAncestor(qbw).Transform(new Point(0, 0)).Y;
line.SetBinding(Line.X1Property, ogX);
line.SetBinding(Line.Y1Property, ogY);
line.SetBinding(Line.X2Property, tgX);
line.SetBinding(Line.Y2Property, tgY);
and the line only draw once. It won't change dynamically. So how is the correct way to bind line points properly?
added photos for giving 'clear pictures' of the problem :v. so basically the lines is drawn when i drag one of those black boxes, and drop to another black boxes, and a line is drawn, but the panel can move around, so the lines have to re-drawn.