c# - Zoom and Move for Canvas -


what's best way implementing zoom (possibly pinch) , move (possibly slide) canvas?

i'm drawing simple stuff (e.g lines, ellipses , more) on canvas , want allow user zoom-in, zoom-out , move view-port freely around.

here go. in xaml code, wrap scroll viewer. this

 <scrollviewer x:name="scrl" zoommode="enabled" horizontalscrollmode="enabled"     verticalscrollmode="enabled" horizontalscrollbarvisibility="visible" verticalscrollbarvisibility="visible" sizechanged="onsizechanged" minzoomfactor="1">         <canvas background="aliceblue" rendertransformorigin="0.5,0.5" x:name="main">             <image source="assets/floorplan.gif" canvas.left="358" canvas.top="84"></image>         </canvas>     </scrollviewer> 

then in c#code put this.

 private void onsizechanged(object sender, sizechangedeventargs args) {          main.width = scrl.viewportwidth;         main.height = scrl.viewportheight; } 

this make canvas zoom pinch , pan enabled.

the image there sample see if zoom function working. works fine.


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -