我正在尝试从解析XAML节点的代码中获取RotateTransform值(度)和ScaleTransform,在本例中为System.Windows.Shapes.Path。
<Path Data="M272,0 L0,0" Height="12.274" Canvas.Left="17.997" StrokeStartLineCap="Flat"
StrokeEndLineCap="Flat" Stroke="White" StrokeThickness="3" StrokeLineJoin="Miter"
Canvas.Top="44.53" Width="146.499" Stretch="Fill" RenderTransformOrigin="0.5,0.5">
<Path.RenderTransform>
<TransformGroup>
<ScaleTransform ScaleX="-1"/>
<SkewTransform/>
<RotateTransform Angle="-90"/>
<TranslateTransform/>
</TransformGroup>
</Path.RenderTransform>
</Path>
使用 RenderTransform,我得到了一个矩阵值,但我无法从中获取角度和 scaleX。
myPath.RenderTransform.Value
如何获取这些信息?
谢谢
好的,
这是解决方案:
TransformGroup tg = myPath.RenderTransform as TransformGroup;
if (tg != null)
{
// Get rotation angle
RotateTransform rt = tg.Children[2] as RotateTransform;
// DoSomething with rt.Angle
// Get scale factor
ScaleTransform st = tg.Children[0] as ScaleTransform;
// DoSomething with st.ScaleX or st.ScaleY
}