title: How to display Unicode control characters in a WPF TextBox?
body: <p>My users do a lot of bi-directional text editing, it is not uncommon for them to sprinkle the text with some <a href="https://en.wikipedia.org/wiki/Left-to-right_mark" rel="nofollow noreferrer">Left-to-right</a> and/or <a href="https://en.wikipedia.org/wiki/Right-to-left_mark" rel="nofollow noreferrer">Right-to-left</a> marks. Sometimes they want to see where those marks are located in the text in order to move or delete them.<br>
  The <code>TextBox</code> control in Windows Forms offers a default context menu with some Unicode-related entries, one of which is <a href="https://i.stack.imgur.com/1STM5.png" rel="nofollow noreferrer">Show Unicode control characters</a>  </p>
  
  <p>Enabling this option will force the control to draw the glyphs defined in the corresponding font for those non-printable characters.</p>
  
  <p>For example, if I set the <code>Text</code> property of a <code>TextBox</code> control to <code>"Hello \u200E World!"</code> and enable this option, I will get the <a href="https://i.stack.imgur.com/yJvbK.png" rel="nofollow noreferrer">LRM character rendered using its glyph as defined in the font file</a> (font used is Segoe UI).  </p>
  
  <p>If we open the Segoe UI font in a font-editing software (I used FontForge), we can see that indeed there are glyphs defined for the <a href="https://i.stack.imgur.com/bF8zk.png" rel="nofollow noreferrer">LRM</a> and <a href="https://i.stack.imgur.com/L0X7Q.png" rel="nofollow noreferrer">RLM</a> code points.  </p>
  
  <p>I also found that <a href="https://msdn.microsoft.com/en-us/library/system.drawing.stringformatflags(v=vs.110).aspx" rel="nofollow noreferrer">StringFormatFlags</a> enumeration can be used to control how these characters are rendered in GDI+, specifically by providing the <code>DisplayFormatControl</code> flag to the <code>StringFormat</code> object:  </p>
  
  <pre><code>private void Form_Paint(object sender, PaintEventArgs e)
  {
      var text = "Hello \u200E World!";
      var g = e.Graphics;
  
      // Will draw LRM symbol with its representative glyph
      var fmt = new StringFormat(StringFormatFlags.DisplayFormatControl);
      g.DrawString(text, Font, Brushes.Black, 10, 10, fmt);
  }
  </code></pre>
  
  <p>However, I haven't found anything similar in WPF TextBox or RichTextBox control: the default context menu provides only Copy, Cut and Paste commands and none of the control properties (including attached ones) seem to enable the drawing of control characters with their font-defined glyphs.</p>
  
  <p>Is there a way to draw Unicode control characters with their representative glyphs in WPF TextBox or RichTextBox without resorting to various hacks, such as replacing those characters with other ones in a converter?</p>