Drawing lines between elements in WPF
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 a开发者_开发知识库t the same rate (like a ViewBox
does).
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.
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.
精彩评论