//-------------------------------------------------- // RoundedTriangle.cs (c) 2008 by Charles Petzold //-------------------------------------------------- using System; using System.Windows; using System.Windows.Controls; using System.Windows.Controls.Primitives; using System.Windows.Media; using System.Windows.Shapes; class RoundedTriangle : Window { [STAThread] public static void Main() { Application app = new Application(); app.Run(new RoundedTriangle()); } public RoundedTriangle() { Title = "Rounded Triangles"; // Create a UniformGrid for showing the triangles UniformGrid uniGrid = new UniformGrid(); uniGrid.Columns = 2; Content = uniGrid; // Create the basic PathGeometry PolyLineSegment polySeg = new PolyLineSegment(new Point[] { new Point(500, 400), new Point(100, 400) }, true); PathFigure pathFig = new PathFigure(new Point(300, 100), new PathSegment[] { polySeg }, true); PathGeometry pathGeo = new PathGeometry(new PathFigure[] { pathFig }); // Create two pens, one thick and one thin Pen penThick = new Pen(); penThick.Brush = Brushes.Blue; penThick.Thickness = 96; penThick.LineJoin = PenLineJoin.Round; Pen penThin = new Pen(Brushes.Blue, 2); // First cell in UniformGrid: 96-pixel wide stroked triangle DrawingImage drawImg = new DrawingImage(new GeometryDrawing(null, penThick, pathGeo)); Image img = new Image(); img.Margin = new Thickness(24); img.Source = drawImg; uniGrid.Children.Add(img); // Second cell in UniformGrid: Widened geometry using 96-pixel wide pen PathGeometry pathGeoWidened = pathGeo.GetWidenedPathGeometry(penThick); drawImg = new DrawingImage(new GeometryDrawing(null, penThin, pathGeoWidened)); img = new Image(); img.Margin = new Thickness(24); img.Source = drawImg; uniGrid.Children.Add(img); // Third cell in UniformGrid: Outlined geometry PathGeometry pathGeoOutlined = pathGeoWidened.GetOutlinedPathGeometry(); drawImg = new DrawingImage(new GeometryDrawing(null, penThin, pathGeoOutlined)); img = new Image(); img.Margin = new Thickness(24); img.Source = drawImg; uniGrid.Children.Add(img); // Fourth cell in UniformGrid: Remove one of the path figures PathGeometry pathGeoCloned = pathGeoOutlined.Clone(); for (int i = 0; i < pathGeoCloned.Figures.Count; i++) { PathFigure fig = pathGeoCloned.Figures[i]; if (fig.Segments.Count == 1) // ie, a PolyLineSegment pathGeoCloned.Figures.Remove(fig); } drawImg = new DrawingImage(new GeometryDrawing(null, penThin, pathGeoCloned)); img = new Image(); img.Margin = new Thickness(24); img.Source = drawImg; uniGrid.Children.Add(img); } }