C#/WPF: LineGeometry with nested UI Elements
I am having problems using LineGeometry for drawing a path between two simple shapes nested in canvas elements.
Here is a quick demo I've put together to demonstrate the problem:
MainWindow.xaml : http://pastebin.ca/2010012
MainWindow.xaml.cs : http://pastebin.ca/2010013
(I thought pasting the code would make life easier for everyone as I am remarkably bad at trying to explain things :) )
In this demo I can succesfully draw a path between the rectangles nested in the parentCanvas, but when I try using the same method for the ellipses I have nested in seperate canvas elements (that are also nested within the parentCanvas) it doesn't seem to do anything.
The reason I am trying to accomplish this is for my actual application I am trying to visualise blocks (canvas elements) with multiple connection points (individual ellipses) so I need to be able to draw paths between these ellipses that are spread across different blocks. A graphical representation of this would be something like: http://img27.imageshack.us/img27/8255/blocksj0.png
Well, I found a workaround to accomplish what I was initially trying to do. Instead of trying to find the child Shape element nested in Canvas elements, I simply calculate a set of coordinates from the position of the Shapes.
This bit of code should explain how I accomplish that:
lg.StartPoint = new Point((Canvas.GetLeft(canvasSrc) + canvasSrc.ActualWidth - 1), (Canvas.GetTop(canvasSrc) + Canvas.GetTop(rectangle5) + rectangle5.ActualHeight / 2)); lg.EndPoint = new Point((Canvas.GetLeft(canvasDest) + 1), (Canvas.GetTop(canvasSrc) + Canvas.GetTop(rectangle6) + rectangle6.ActualHeight / 2));
Posting this in case someone else finds it useful :)