I am getting a eroor from my code, i cant trace the issue/bug . here is my code bit...
我从我的代码中得到了一个eroor,我无法追踪问题/错误。这是我的代码位...
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 post again,..the error raised from the*** mt.Matrix = mx; *** statement..
我再次编辑了帖子,.. *** mt.Matrix = mx引发的错误; ***声明..
What could be the issue i am using a WPF(win) application.
可能是我使用WPF(win)应用程序的问题。
2 个解决方案
#1
Instead of assigning to the read-only matrix property, try this:
尝试这样做,而不是分配给只读的矩阵属性:
item.RenderTransform = new MatrixTransform(mx);
#2
The RenderTransform property of UIElement is initially assigned as a MatrixTransform instance whose IsSealed and IsFrozen properties are both true, instead of a null reference. It should be noticed.
UIElement的RenderTransform属性最初被指定为MatrixTransform实例,其IsSealed和IsFrozen属性都为true,而不是null引用。应该注意到。
#1
Instead of assigning to the read-only matrix property, try this:
尝试这样做,而不是分配给只读的矩阵属性:
item.RenderTransform = new MatrixTransform(mx);
#2
The RenderTransform property of UIElement is initially assigned as a MatrixTransform instance whose IsSealed and IsFrozen properties are both true, instead of a null reference. It should be noticed.
UIElement的RenderTransform属性最初被指定为MatrixTransform实例,其IsSealed和IsFrozen属性都为true,而不是null引用。应该注意到。