tags:

views:

291

answers:

2

What is a good approach for drawing lines between elements in WPF?

I have a view in my application with several buttons that make up a diagram. They scale and move depending on the view's size and shape. I would like to indicate a relationship between some of the buttons using a line.

I am not using a Canvas to lay everything out because I want the buttons' relative positions to be dynamic, and I do not want everything to scale at the same rate (like a ViewBox does).

A: 

You need to create a container Control to be able to define the relationship of the buttons.

Once this is established, drawing the line should be a matter of overriding OnRender, finding the position of each child control, and using the DrawingContext to draw the line.

Will Eddins
A: 

My solution was to use a Grid with a Canvas and my elements in the same cell. I drew the lines in the Canvas in my code-behind file.

emddudley