我试图从解析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 ,我得到一个 Matrix 值,我无法从中获得角度和scaleX。
myPath.RenderTransform.Value
我如何获得这些信息?
谢谢
答案 0 :(得分:-1)
好的,这是解决方案:
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
}