2009-07-09 31 views
3

我從我的代碼中獲取了一個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); 
     } 
    } 

我再次編輯後,...從引發的錯誤*** mt.Matrix = MX; ***聲明..

什麼可能是我使用WPF(勝利)應用程序的問題。

+0

什麼是錯誤? – AlbertoPL 2009-07-09 13:11:39

回答

5

而是分配給只讀矩陣特性,試試這個:

item.RenderTransform = new MatrixTransform(mx); 
+0

我在將圖像縮放到鼠標位置時遇到了問題,並花費了大量時間進行搜索。與其他解決方案一起,我發現它在4行代碼中做了訣竅!謝謝! – EpiGen 2015-08-13 15:21:32

1

UIElement的RenderTransform屬性最初分配作爲其IsSealed和ISFROZEN性能都是真MatrixTransform實例,而不是空參考。應該注意。

相關問題