2013-08-07 181 views
3

我完全厌倦将Rectangle添加到路径图中。下面是我试过的代码,但它正确不结果为Rectangle如何将矩形添加到PathFigure WPF

PathGeometry geom = new PathGeometry(); 
Geometry g = new RectangleGeometry(myrectangel); 
geom.AddGeometry(g); 

PathFigureCollection collection = geom.Figures; 
pathfigure = collection[0]; 

有没有其他办法?

回答

5

您可以使用GeometryGroup组合几何图形。 A GeometryGroup根据一个或多个对象创建复合几何。

GeometryGroup gg = new GeometryGroup();    
gg.Children.Add(new RectangleGeometry(new Rect(0, 0, 100, 100))); 
gg.Children.Add(new RectangleGeometry(new Rect(100, 100, 100, 100))); 
gg.Children.Add(new RectangleGeometry(new Rect(200, 200, 100, 100))); 

System.Windows.Shapes.Path path = new System.Windows.Shapes.Path(); 
path.Data = gg; 
path.Fill = Brushes.Blue; 
+0

感谢Nitesh ......但我需要将它添加到的PathFigure,最后使用它,因为我有很多rectagles像上面.... /// –

+0

你可以用'GeometryGroup'。 – Nitesh

+0

多数民众赞成在酷Nitesh,。一个想法...谢谢 –