WPF通过操作调整矩形大小无法保持比例 [英] WPF resize rectangle by manipulation does not maintain ratio

查看:86
本文介绍了WPF通过操作调整矩形大小无法保持比例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个小问题.我正在WPF上设计一个可在Windows 8.1平板电脑上运行的应用程序.我正在构建一种裁剪"软件(除其他外).

I'm facing a little problem. I'm designing an application on WPF that will run on Windows 8.1 tablet. I'm building a sort of "cropping" software (among other things).

为此,我在窗口上创建了一个Rectangle,并按照Microsoft的演练进行操作: http://msdn.microsoft.com/zh-cn/library/vstudio/ee649090(v = vs.100).aspx

To do so, I've created a Rectangle on my window, and followed the Microsoft walkthrough here: http://msdn.microsoft.com/en-us/library/vstudio/ee649090(v=vs.100).aspx

因为我不想保持矩形正方形,所以我通过在 ManipulationDelta

Because I don't want to keep my rectangle square, I change their example by setting Scale.Y on ManipulationDelta

这是更改后的代码

rectsMatrix.ScaleAt(e.DeltaManipulation.Scale.X,
                    e.DeltaManipulation.Scale.Y,
                    e.ManipulationOrigin.X,
                    e.ManipulationOrigin.Y);

但是,尽管如此,当我捏紧调整大小时,我的矩形仍会调整为正方形.我不明白为什么或如何解决这个问题.

But despite this, my rectangle is still resizing to square when I pinch to resize. I don't understand why or how to workaround this.

推荐答案

WPF操作API不支持独立缩放X和Y,同时还可以旋转.

The WPF manipulation APIs don't support independently scaling X and Y while also being able to rotate.

进行此练习...绘制一个矩形,并在其上的某个地方放置两个点.现在绘制相同的矩形,使这两个点沿对角线彼此远离.根据这些点之间的增量,您将如何确定用户是尝试旋转还是独立缩放X与Y的比例,还是同时进行两者?我们所拥有的信息有限,这完全是模棱两可的.

Do this exercise... draw a rectangle and put two dots somewhere on it. Now draw that same rectangle with those two dots moved diagonally away from each other. Based on the deltas between those dots, how would you decide if the user was trying to rotate or independently scale X vs. Y or do both at the same time? It's entirely ambiguous with the limited information we have.

这就是为什么应用程序通常最终会具有特定的句柄",而您需要触摸这些特定的句柄"才能显式进入旋转"模式或"X/Y调整大小"模式.从实现的角度来看,您将处理该句柄上的操作事件(与控件本身分开),并相应地设置ManipulationOrigin和ManipulationStartingEventArgs.Mode.

This is why apps will often end up having specific 'handles' you need to touch to explicitly go into 'rotate' mode or 'X/Y resize mode'. From an implementation perspective, you would handle the manipulation events on that handle (separate from the control itself) and set ManipulationOrigin and ManipulationStartingEventArgs.Mode accordingly.

(免责声明:我是几年前创建这些API的团队的一员)

这篇关于WPF通过操作调整矩形大小无法保持比例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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