title: WPF Custom shape
body: <p>I need to create a custom shape to add on a WPF form. The shape is just a triangle. If you are wondering, yes, I can do that with a Polygon in XAML with this:</p>
  
  <pre><code>&lt;Polygon Fill="LightBlue" Stroke="Black" Name="Triangle"&gt;
    &lt;Polygon.Points&gt;
      &lt;Point X="0" Y="0"&gt;&lt;/Point&gt;
      &lt;Point X="10" Y="0"&gt;&lt;/Point&gt;
      &lt;Point X="5" Y="-10"&gt;&lt;/Point&gt;
    &lt;/Polygon.Points&gt;
  &lt;/Polygon&gt;
  </code></pre>
  
  <p>The problem is that we need to bind a property from somewhere else that ultimately determines the size of the shape. So, I wrote a simple extension of the shape class like this:</p>
  
  <pre><code>public class Triangle:Shape
  {
      private double size;
  
      public static readonly DependencyProperty SizeProperty = DependencyProperty.Register("Size", typeof(Double), typeof(Triangle));
  
      public Triangle() {            
      }
  
      public double Size
      {
          get { return size; }
          set { size = value; }
      }
  
      protected override Geometry DefiningGeometry
      {
          get {
  
              Point p1 = new Point(0.0d,0.0d);
              Point p2 = new Point(this.Size, 0.0d);
              Point p3 = new Point(this.Size / 2, -this.Size);
  
              List&lt;PathSegment&gt; segments = new List&lt;PathSegment&gt;(3);
              segments.Add(new LineSegment(p1,true));
              segments.Add(new LineSegment(p2, true));
              segments.Add(new LineSegment(p3, true));
  
              List&lt;PathFigure&gt; figures = new List&lt;PathFigure&gt;(1);
              PathFigure pf = new PathFigure(p1, segments, true);
              figures.Add(pf);
  
              Geometry g = new PathGeometry(figures, FillRule.EvenOdd, null);
  
              return g;
          }
      }
  
  }
  </code></pre>
  
  <p>I thought that was good but the shape does not show up anywhere on the form. So, I am not sure if the DefiningGeometry method is well written. And if I cannot see anything very likely is not.
  Thanks!</p>