本文介绍了在WPF中进行缩放变换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有画布。在那个画布上,我绘制了两个线对象。在PreviewMouseWheel事件中,我通过ScaleTransform缩放画布的内容。假设在缩放之前,Line从0开始并在50.结束。然后下一行从50开始并在70结束。这两个值是X坐标。我正在使用ScaleTransform和RenderTransform。
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;
canvas.Width=initialCanvasWidth*scaleFacotr
假设
Suppose
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}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Canvas Height="12000" Margin="0,30,0,0" Background="Transparent" Name="front_canvas" ClipToBounds="True"
PreviewMouseWheel="OnPreviewMouseWheel"
Width="{Binding CanvasWidth, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<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" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
推荐答案
这篇关于在WPF中进行缩放变换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!