在 wpf 中平移变换后对象无法正确旋转?
我的画布上有几个从面板类继承的自定义控件,在运行时使用 rendertransform=(.5,.5) 动态添加到其中。但是当应用平移变换(50,50)并将其旋转100度时,它并没有原地旋转,而是以50的半径旋转,为什么? 我做错了什么吗?
I have canvas with several cutom controls inherited from panel class, dynamically added to it at runtime with rendertransform=(.5,.5). But when apply translate transform (50,50) and rotate it by 100 degrees, it does not rotate on its place, it rotates in radius of 50, why?
Am I doing wrong something ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
变换不可交换,您应该在应用平移之前应用旋转。
通常,您有一个 TransformGroup,那么您可以更改其子级的顺序,如果这在某种程度上不是一个选项,因为某些变换是从父级“继承”的,您可以使用它们的逆来取消先前的变换(在翻译的情况下)应该将目标移回原点),然后您可以将其旋转到位,并再次应用原始变换。
该文档是您的朋友,以下是 的内容
TransformGroups
:Transformations are not commutative, you should apply the rotation before applying the translation.
Often you have a TransformGroup, then you can just change the order of its children, if this is somehow not an option because some transform is "inherited" from a parent you can nullify prior transforms using their inverse (in the case of a translation that should move the target back to the origin), then you can rotate it in place, and apply the original transform again.
The documentation is your friend, here is what can be found for
TransformGroups
:如果它以50的半径旋转,那是因为你的原点是错误的。
您只需将
CenterX
和CenterY
属性均设置为50
即可更改RotateTransform
的原点。案件。If it rotates with a radius of 50, it's because your origin is wrong.
You just need to change the origin of your
RotateTransform
by setting theCenterX
andCenterY
properties both to50
in this case.