I have to draw several arrows between buttons and the UI shall be able to recalculate its position during resizing.
For this I built a custom shape class which is able to draw an arrow between two points.
The XAML to insert this class looks like this:
<customui:Arrow x:Name="Transition12"
X1="150" Y1="480" X2="290" Y2="200"
HeadHeight="5" HeadWidth="5"
Stroke="Black"
StrokeThickness="2" />
Next step would be to calculate the edge of a button to connect the start point X1/Y1 or the end point of the arrow X2/Y2 to the button
At the moment I do calculate this manually in the sizeChanged Event in CodeBehind:
Size size = Btn1.RenderSize;
Point offset = new Point(size.Width / 2, size.Height);
Point anchorPointBtn1 = Btn1.TranslatePoint(new Point(0, 0), this);
anchorPointBtn1.Offset(offset.X, offset.Y);
Transition12.X1 = anchorPointBtn1.X;
Transition12.Y1 = anchorPointBtn1.Y;
Doing this with every anchor point where an arrow starts or ends, will give me what I need.
But it is all static and when i want to calculate another anchor point I have to calculate it manually.
So, the best thing would be to built a button class which provides this anchor points as properties like in the picture below:
Is there a way to easy derive the button class and add these anchor points as dependency property? Or even easier is there a nuget available which provides this functionality?