在WPF中进行缩放变换 [英] Working of scale transform in WPF

查看:92
本文介绍了在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>

推荐答案

行具有笔画粗细;这就是控制线上点有多少像素/设备单位的原因。


如果你想要扩展以外的厚度是你所改变的x和y(和z)。
"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).


这篇关于在WPF中进行缩放变换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆