I have created a custom class derived from Canvas, which contain elements which will be derived from Visual. The canvas also contains a grid which i have created by creating lines.
Now for zooming, i remove everything from the canvas, resize the canvas (which is placed inside ScrollViewer), and redraw everything that is on it. Is there a better way to implement zoom, something that is provided, which allows me to scroll and zoom, and somehow create a viewport, that i can move and resize (for scrolling and zooming)? Because my concern is that soon there will be complex shapes, curves and points placed on the canvas, and maybe by the thousands, and things will get pretty slow if i use the approach that i am using currently.
Please tell if there is a better way.
If you don’t want to affect the layout, then I would suggest you to use
RenderTransforminstead ofLayoutTransform. So something like this:You may also would like to use
RenderTransformOrigindependency property of UIElement, and you can do zoom-in and out, from code behind changing the value ofScaleXandScaleY.By the way, you also would like to read these before doing what you want to do: