我要做的就是myObject
在我UserControl
使用的方法中间居中,我MatrixTransform
用于缩放和旋转。
.xaml
<Grid>
<MyObject x:Name="myObject">
<MyObject.RenderTransform>
<MatrixTransform />
</MyObject.RenderTransform>
</MyObject>
</Grid>
。CS
public void CenterMyObject()
{
Point layoutCenter = myObject.PointFromScreen(new Point(ActualWidth / 2, ActualHeight / 2));
var transform = myObject.RenderTransform as MatrixTransform;
var matrix = transform.Matrix;
matrix.TranslatePrepend(layoutCenter.X, layoutCenter.Y);
transform.Matrix = matrix;
}