无法仅在 x 轴上缩放路径的某些子项

unable to scale the path's certain children in x axis only

我的代码是在 wpf 中绘制水平线和垂直线的组合。我只想缩放水平线。此代码同时缩放水平和垂直。

Path path = new Path();
            SolidColorBrush brush = new SolidColorBrush();
            brush.Color = Colors.Red;
            path.Stroke = brush;
            path.StrokeThickness = 4;
             LineGeometry lineGeometry = new LineGeometry();
            lineGeometry.StartPoint = new Point(10, 100);
            lineGeometry.EndPoint = new Point(100, 100);
            LineGeometry lineGeometry2 = new LineGeometry();
            lineGeometry2.StartPoint = new Point(100, 100);
            lineGeometry2.EndPoint = new Point(100, 200);

            LineGeometry lineGeometry3 = new LineGeometry();
            lineGeometry3.StartPoint = new Point(100, 200);
            lineGeometry3.EndPoint = new Point(200, 200);
            LineGeometry lineGeometry4 = new LineGeometry();
            lineGeometry4.StartPoint = new Point(200, 200);
            lineGeometry4.EndPoint = new Point(200, 100);
            LineGeometry lineGeometry5 = new LineGeometry();
            lineGeometry5.StartPoint = new Point(200, 100);
            lineGeometry5.EndPoint = new Point(300, 100);
            GeometryGroup geometryGroup = new GeometryGroup();
            geometryGroup.Children.Add(lineGeometry);
            geometryGroup.Children.Add(lineGeometry2);

            geometryGroup.Children.Add(lineGeometry3);

            geometryGroup.Children.Add(lineGeometry4);

            geometryGroup.Children.Add(lineGeometry5);

            path.Data = geometryGroup;


            var scaling = new ScaleTransform(2, 1);

            path.RenderTransform = scaling;
            canvas1.Children.Add(path);

如果只想缩放几何图形,而不是 Path 的 StrokeThickness,请不要设置 Path 的 RenderTransform。

相反,直接变换 Geometry:

geometryGroup.Transform = new ScaleTransform(2, 1);
path.Data = geometryGroup;

canvas1.Children.Add(path);