Click here to Skip to main content
15,941,071 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a canvas. And on that canvas, I have drawn two line objects. On the PreviewMouseWheel event I am zooming the content of canvas through ScaleTransform. Suppose before zooming the Line was starting at 0 and ending at 50.Then Next line was starting at 50 and ending at 70.These value are X cordinates of the two lines. I am using ScaleTransform and RenderTransform.
ScaleTransform scaleTransform = new ScaleTransform(scaleFacotr, 1);
canvas.RenderTransform = scaleTransform;


scaleFacotr value is  2. We are multiplying x coordinate of  every point with 2 and multiply ycoordinate of every point  with 1. This thing I understand. I  want to confirm does it also mean the point on a line which was taking 1 pixel will now take 2 pixels along x axis

What I have tried:

<pre> <ItemsControl ItemsSource="{Binding Lines}">
                            <Canvas  Height="12000" Margin="0,30,0,0"  Background="Transparent"  Name="front_canvas" ClipToBounds="True" 
                                      Width="{Binding CanvasWidth, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" 

                            <Line   X1="{Binding From.X , Mode=TwoWay}" Y1="{Binding From.Y, Mode=TwoWay}" Stretch="None"
                            X2="{Binding To.X, Mode=TwoWay}" Y2="{Binding To.Y, Mode=TwoWay}" 
                            Stroke="OrangeRed" StrokeThickness="1" 
                            Loaded="Line_Loaded" />   

Updated 21-Mar-19 6:12am

1 solution

"Lines" have a "stroke thickness"; that's what controls how many pixels / device units are on a "point on the line".

The "thickness" is what you vary if you want to scale other than x and y (and z).
Share this answer
hamid18 21-Mar-19 13:07pm    
This means when we use ScaleTransform and render transform on Canvas, even though the line becomes bigger in size in the view. Still the points on the line takes 1 pixel if I do not change the stroke thickness.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900