[英]WPF cast Button RenderTransform to RotateTransform
I want my button's rotation value. 我想要按钮的旋转值。 People were suggested like this code
人们被建议像这样的代码
RotateTransform rTransform = MyButton.RenderTransform as RotateTransform;
double angle = rTransform.Angle;
But Compiler Thorw this Exception 但是编译器Thorw这个异常
An unhandled exception of type 'System.InvalidCastException' occurred in DynamicButtonP.exe.
Additional information: Unable to cast a 'System.Windows.Media.MatrixTransform' the object type 'System.Windows.Media.RotateTransform' format.
why I couldn't casting? 为什么我不能铸造?
You forgot to initialize the RenderTransform
property of the Button. 您忘记了初始化Button的
RenderTransform
属性。 Its default value is Transform.Identity
, which is a MatrixTransform. 它的默认值为
Transform.Identity
,它是一个MatrixTransform。
Initialize the property eg in XAML: 初始化属性,例如在XAML中:
<Button x:Name="MyButton" ...>
<Button.RenderTransform>
<RotateTransform/>
</Button.RenderTransform>
</Button>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.