0

In my WPF application I have a control that acts like a zoom box. You can zoom and drag its content. In my case this content is a grid that contains an image and some UserControls. These UserControls have to be positioned ontop of the image to highlight some segments of that image.

Here is an example (this is not an actual use case): Zoombox content

My question is, how should I position those red rectangles (what is the better practise here)?

  1. By replacing the grid with a canvas and use Canvas.SetLeft resp. Canvas.SetTop?

or

  1. By manipulating the RenderTransform of those rectangles?

Note: The rectangles are interactive (they have to interact with the mouse and maybe some other input devices).

Timo
  • 9,269
  • 2
  • 28
  • 58
  • In my opinion - it is a `Canvas`. – Peter Jul 20 '17 at 07:49
  • The 'problem/advantage' with a RenderTransform of the rectangles, that the BorderThickness will be transformed also. So it will be thicker or thinner while zooming.. This will not be the case when only changing the `SetLeft/SetTop` – Jeroen van Langen Jul 20 '17 at 07:53
  • 1
    @JeroenvanLangen Not really. You can use `ValueConverter` to convert the thickness of the border and "reverse" scaling effect. – mrogal.ski Jul 20 '17 at 07:58
  • @JeroenvanLangen That is not a problem in my use case. The border is affected in either way equally. And btw my UserControls (which replace the rectangles) can handle the zoom change. – Timo Jul 20 '17 at 07:58
  • @m.rogalski That is actually a nice way to implement that (though its offtopic). Thanks. – Timo Jul 20 '17 at 08:00
  • In my previous job I was implementing an auto-scaled elements ( similar to the ones you have ) and I am 100% sure you can achieve this using simple `RenderTransform` and some converters to "inverse" the scale. This wont be hard as long as you do not want to implement rotation in it. – mrogal.ski Jul 20 '17 at 08:02
  • I think it's a ducktape solution. – Jeroen van Langen Jul 20 '17 at 14:04

0 Answers0