使用代码(如下所示)我有一个错误说:
'object' does not contain a definition for 'RenderTransform' and no extension method 'RenderTransform' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly language
我不知道为什么这显示为错误,因为根据大多数示例(此)这应该有效。代码:
public void Rotate(object sender, int rotationAmount, int centerX, int centerY)
{
RotateTransform rotate = new RotateTransform(rotationAmount);
rotateTransform.CenterX = centerX;
rotateTransform.CenterY = centerY;
sender.RenderTransform = rotateTransform;
}
答案 0 :(得分:2)
您必须强制 sender
(声明为object
)到适当的类型:
UIElement element = sender as UIElement;
if (element != null)
element.RenderTransform = rotateTransform;
答案 1 :(得分:0)
您需要将sender
转换为具有RenderTransform
属性的类型。
答案 2 :(得分:0)
您的sender
类型为object
,绝对没有RenderTransform
方法。
您应该将其转换为您需要的类型。