如何在 WPF 中获取 UI 元素的旋转值 [英] How to get the rotation value of a UI Element in WPF
本文介绍了如何在 WPF 中获取 UI 元素的旋转值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经知道如何分配旋转值 (element.RenderTransform = new RotateTransform(x)),但是如何获取元素的旋转值?
I've figured out how to assign a rotation value (element.RenderTransform = new RotateTransform(x)), but how do I get the rotation value of the element?
例如,如果我想让一个 ui 元素与另一个 ui 元素具有相同的旋转角度,我该怎么做?
For example, if I wanted to make one ui element have the same rotation angle as another ui element, how would I do that?
推荐答案
您可以通过以下方式获取旋转值:
You can get the rotation value by doing:
RotateTransform rotation = element.RenderTransform as RotateTransform;
if (rotation != null) // Make sure the transform is actually a RotateTransform
{
double rotationInDegrees = rotation.Angle;
// Do something with the rotationInDegrees here, if needed...
}
如果你只想让另一个 UIelement 以同样的方式旋转,你可以只分配相同的变换:
If you want to just make another UIelement rotate in the same way, you can just assign the same transform:
element2.RenderTransform = element.RenderTransform;
这篇关于如何在 WPF 中获取 UI 元素的旋转值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文