'System.Windows.Media.PointCollection'必须将IsFrozen设置为false才能修改

时间:2017-07-18 07:49:45

标签: .net wpf clone transformation rotatetransform

其他信息:“System.Windows.Media.PointCollection”类型的指定值 必须将IsFrozen设置为false才能修改。

我有动态调整大小的路径。当我调整大小而没有任何旋转时它工作正常。 但是一旦我使用RotateTransform然后当我旋转这条路径 尝试调整大小。然后它给出了我上面提到的错误。 为变更点调用的代码是下面的Moving类的setter:

public Moving(PolyLineSegment poly, int index, Vector offset) {
    PointCollection ps = poly.Points;
    // ps.IsFrozen = false;  //I tried to do this but i cannot make it true;
    getter = () => new Point(ps[index].X + offset.X, ps[index].Y + offset.Y);;
    setter = (p) => //This is called with new points update
        {
            PointCollection ps1 = ps.Clone(); //I tried to clone but still out of luck,
            Point pt = new Point(ps1[index].X, ps1[index].Y);
            pt.X = p.X - offset.X;
            pt.Y = p.Y - offset.Y;
            ps[index] = pt; //Here i assign new points, IT gives exception at this line
            //ps[index] = new Point(p.X - offset.X, p.Y - offset.Y);
        };
}

当Path未旋转但旋转时出现异常时,代码工作正常。请参阅下面的代码:

Path path = (System.Windows.Shapes.Path)ElementBeingRotated;
rotateTrans = new RotateTransform();
rotateTrans.Angle = 90;
rotateTrans.CenterX = path.ActualWidth / 2;
rotateTrans.CenterY = path.ActualHeight / 2;
PathGeometry geometry = PathGeometry.CreateFromGeometry(path.Data);
PathGeometry clonedGeo = geometry.Clone();
clonedGeo.Transform = rotateTrans; // applying some transform to it
result = clonedGeo.GetFlattenedPathGeometry();
path.Data = result;

如何在RotateTransform之后调整路径大小以及旋转后不调整大小的原因?

0 个答案:

没有答案