Unable to set property on "Identity" object because it is in read-only state

I get eroor from my code, I can not track the problem / error. here is my code bit ...

private void DoArrange()
    {
        Point center = new Point((this.Width - ItemSize) / 2, (this.Height - ItemSize) / 2);
        double radiusX = center.X;
        double radiusY = center.Y;
        double scale = ScalePerspective;

        for (int i = 0; i < Children.Count; i++)
        {
            UIElement item = Children[i];
            double radians = (double)item.GetValue(CarouselPanel.AngleProperty);

            Point p = new Point(
                                (Math.Cos(radians) * radiusX) + center.X,
                                (Math.Sin(radians) * radiusY) + center.Y
                               );

            if (item.RenderTransform == null)
            {
                item.RenderTransform = new MatrixTransform();
                item.RenderTransformOrigin = new Point(0.5, 0.5);
            }
            MatrixTransform mt = item.RenderTransform as MatrixTransform;
            double scaleMinusRounding = p.Y / (center.Y + radiusY);
            double scaleX = Math.Min(scaleMinusRounding + scale, 1.0);
            double scaleY = Math.Min(scaleMinusRounding + scale, 1.0);
            Matrix mx = new Matrix(scaleX, 0.0, 0.0, scaleY, 0.0, 0.0);

            *** mt.Matrix = mx; ***

            item.RenderTransform = mt;

            int zIndex = (int)((p.Y / base.Height) * 50);
            item.SetValue(Canvas.ZIndexProperty, zIndex);
            Rect r = new Rect(p.X, p.Y, ItemSize, ItemSize);
            item.Arrange(r);
        }
    }

I edited the message again, .. the error raised from *** mt.Matrix = mx; *** expression..

What could be the problem, I am using a WPF (win) application.

+3
source share
2 answers

Instead of assigning a read-only matrix property, try the following:

item.RenderTransform = new MatrixTransform(mx);
+5
source

The RenderTransform property for UIElement is initially assigned as an instance of MatrixTransform, the IsSealed and IsFrozen properties are both true, instead of a null reference. It should be noted.

+1
source

Source: https://habr.com/ru/post/1712196/


All Articles