wpf - 无法在对象 'Identity' 上设置属性,因为它处于只读状态

标签 wpf

我的代码出现错误,我无法追踪问题/错误。这是我的代码位...

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);
        }
    }

我再次编辑了帖子,..从*** mt.Matrix = mx; 引发的错误***声明..

我使用 WPF(win) 应用程序可能是什么问题。

最佳答案

不要分配给只读矩阵属性,试试这个:

item.RenderTransform = new MatrixTransform(mx);

关于wpf - 无法在对象 'Identity' 上设置属性,因为它处于只读状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1103762/

相关文章:

c# - XAML 中的 WPF StringFormat 和本地化

WPF改变亮度

wpf - 在 MVVM WPF 中使用工作单元设计模式/NHibernate session

c# - 在 WPF 中绑定(bind)源时图像未显示

c# - 如何在附加行为中使用单例计时器来更改 ListView 项目的背景颜色?

c# - System.IO.Ports 5.0 NuGet 包在我的解决方案中不起作用

c# - 向 DataGrid 添加大量项目时 UI 卡住

c# - MenuItem 背景不透明度而不是其文本?

wpf - 是否可以在 WPF TabControl 中左对齐标题?

c# - 更改 UserControl 中的值时,通过 UserControl 的绑定(bind)中断