0

I'm trying to create a WPF program where the user can drag adorners on the vertices of a polygon to stretch and resize the shape. When the vertex is grabbed by the mouse and dragged it will redraw the polygon with the vertex in that position. I'm aware of the width/height fields that can be modified to rezise the overall shape but what I want to do is have only the vertex position changed and the polygon lines to redraw essentially a new polygon with the new vertex positions.

So far I have the ability to draw static sized polygons(rectangles) and have adorners positioned on the corners but the problem seems to be that when you drag the adorner the adorner box does not stay on the polygon vertex. I believe this is because the adorner is drawn relative to the position of the polygon (its adorned element) rather than the overall canvas it is being drawn on.

I'm wondering if there is a way to simply position the adorner to a screen coordinate rather than relative to the shape. My logic is that I can simply draw an adorner box using onRender() at the polygon's vertex as the location and have the mouse drag function get the position of the mouse and change the polygon's vertex point directly thereby also changing the coordinates where the adorner is drawn. so far I have not been able to find a way to do this. is this even possible? Can an adorner be drawn always on the vertex so that it snaps to it when the shape is resized? If not does anyone know another way to do this?

Erwin
  • 4,757
  • 3
  • 31
  • 41

1 Answers1

0

After playing around with it a bit I came to the solution. First off it is important you understand a little more about how WPF actually handles rendering for adorners. This really helped me and gave a good explanation of how it worked: Why does my adorner not re-render when the element it's applied to changes?

The main issue it seemed for me is that I needed to call invalidateVisual() to manually call the OnRender() function to make the changes to the adorner/polygon vertex positions. The other thing is to make sure that your Stretch property is set to none. I had it orginaly set to fill and it will offset the points and not allow it to render properly. After that it was a matter of making sure the adorners OnRender() function draws the adorner on the vertex of the polygon by passing the polygon.points porperty to the draw call of the adorner.

Community
  • 1
  • 1