title: Wavy underlines as a TextDecoration: what I am doing wrong?
body: <p>I want to create <a href="https://stackoverflow.com/questions/632450/wavy-underlines-in-a-flowdocument">wavy underlines</a> using TextDecoration (in a control similar to RichTextBox).</p>
  
  <p>I did the following thing:</p>
  
  <pre><code>private static Pen CreateErrorPen() {
      var geometry = new StreamGeometry();
      using (var context = geometry.Open()) {
          context.BeginFigure(new Point(0.0, 0.0), false, false);
          context.PolyLineTo(new[] {
              new Point(0.75, 0.75),
              new Point(1.5, 0.0),
              new Point(2.25, 0.75),
              new Point(3.0, 0.0)
          }, true, true);
      }
  
      var brushPattern = new GeometryDrawing {
          Pen = new Pen(Brushes.Red, 0.2),
          Geometry = geometry
      };
  
      var brush = new DrawingBrush(brushPattern) {
          TileMode = TileMode.Tile,
          Viewport = new Rect(0.0, 1.5, 9.0, 3.0),
          ViewportUnits = BrushMappingMode.Absolute
      };
  
      var pen = new Pen(brush, 3.0);
      pen.Freeze();
  
      return pen;
  }
  </code></pre>
  
  <p>This almost works, but depending on the underlined word position in text, underlines often show up as a pattern of several superimposed waves. Also the underlines are a bit blurry even when they are correct (wpf problem with drawing between pixels, I suppose).</p>
  
  <p>My solution was kind of a trial-and-error, so I might have gone a wrong way, especially with Viewport/ViewportUnits.</p>
  
  <p>What am I doing wrong and is there a way to get crisp underlines?</p>
  
  <p>Thanks in advance.</p>