2011-12-06 4 views
1

나는이 캔버스에 여러 요소가 있습니다. 나는이 요소들의 경계를 따로 얻을 수있다.경계 계산 여러 요소 silverlight

어떻게 해당 데이터가있는 모든 요소의 경계를 계산할 수 있습니까?

사물을 분명히하는이 그래픽 표현을보실 수 있습니다.

Graphical representation

답변

1

목록으로 요소의 각 모서리에 대한 포인트 값을 당긴 후 최소 및 최대 X를 얻을 Y는이 사이트는 각각의 값을 찾는 방법을 보여줍니다

 List<Point> Points = new List<Point>(); 

     foreach (UIElement x in cvsMain.Children.Where(ui => ui.GetType() == typeof(Rectangle))) 
     { 
      // Obtain transform information based off element you need to find position within 
      GeneralTransform gt = x.TransformToVisual(cvsMain); 

      // Find the four corners of the element 
      Points.Add(gt.Transform(new Point(0, 0))); 
      Points.Add(gt.Transform(new Point((x as Rectangle).Width, 0))); 
      Points.Add(gt.Transform(new Point(0, (x as Rectangle).Height))); 
      Points.Add(gt.Transform(new Point((x as Rectangle).Width, (x as Rectangle).Height))); 
     } 

     Double Left = Points.Min(p => p.X); 
     Double Right = Points.Max(p => p.X); 
     Double Top = Points.Min(p => p.Y); 
     Double Bottom = Points.Max(p => p.Y); 

값 코너 http://forums.silverlight.net/t/12160.aspx/1

+1

포인트 콜렉션을 생략하고 루프 안의 x, y 코드의 최소/최대를 볼 수도 있습니다. –

+0

고마워요, 이걸 소용돌이 칠 거예요. – tutu