wpf - ScaleTransform applying Translate effects -
I want to create zooming controls, which can be operated with the mouse wheel Scroll up -> Zoom in; Scroll down -> Zoom out - Besides, I want to be located in the zoom center where the mouse pointer is. So that anyone can always zoom in on the spot, where the mouse cursor is.
Looks simple enough, yet I can not work.
To implement a grid and ScaleTransform
When I first zoom, it works in that place and zooms, but then, if I move the cursor to another place and try to zoom a bit higher, then < Code> grid is offset and my starting center is closed.
What is the reason? How can this fix?
My code:
The main window of the class resized as a Trans Transform Dim Scale Double = 1 Private Sub defGrid_MouseWheel (as the Sender object, and MousewayAlientErgance handles) Deff Grid handles Mouse Volume E If Delta & gt; 0 then scale = scale + 0.1 end if e delta & lt; 0 then scale = scale - 0.1 end if trans .centerx = e. Gatepace (def Grid) X Trans.Scenter Y = E. Gatepace (defrgr) Or trans. Scale X = Scale Trans. Scale Y = Scale Defrild. RenderTransformForm = Trans and Sub End Class and xaml:
& lt; Window x: Class = "Main Window" xmlns = "http://schemas.microsoft.com/ Winfx / 2006 / xaml / Presentation" xmlns: x = "http://schemas.microsoft.com/winfx/2006/xaml "Title =" main window "height =" 350 "width =" 525 "previewmouse vehyl =" windowprov્યુmochelle "& gt; & Lt; Grid X: Name = "Def Grid" Horizontal Alignment = "Left" Height = "291" margin = "19,10,0,0" vertical alignment = "top" width = "475" & gt; & Lt; Canvas horizontal alignment = "left" height = "254" margin = "137,10,0,0" workspaceElement = "top" width = "195" & gt; & Lt; Canvas.Background & gt; & Lt; ImageBrush ImageSource = "TestImage.jpg" /> & Lt; /Canvas.Background> & Lt; / Canvas & gt; & Lt; / Grid & gt; & Lt; / Window & gt; For reference only, there is a canvas image on the grid.
This is a bit more complicated, unfortunately if you do not think you need a scrollbar, answer See here (I have not found VB-specific examples, so they are C #): If you also need a scrollbar, you have to scroll through the mouse pointer. In that case you need something like this:
Comments
Post a Comment