title: How to display short read only FlowDocument in a label-like control
body: <p>I am looking for a way to present short <code>FlowDocument</code> strings in a label-like control.</p>
  
  <p>In WPF the user can input text into a <code>RichTextBox</code>. The result is a <code>FlowDocument</code> string.
  I'm looking for a way to present that text in a <code>Label</code>, in which:</p>
  
  <ol>
  <li>The user should not be able to edit or select (with the mouse) the text.</li>
  <li>There should be no scroll bars - like in a normal label the control should expand to accommodate all the text.</li>
  <li>If the user scrolls while the mouse is on the label, the control that should scroll is the parent of the control</li>
  <li>The control should be as lightweight as possible.</li>
  </ol>
  
  <p>I have the following implementation that inherits <code>FlowDocumentScrollViewer</code> but I am sure there must be a better implementation (possibly inheriting other control than <code>FlowDocumentScrollViewer</code>).</p>
  
  <pre><code>public class FlowDocumentViewer : FlowDocumentScrollViewer
  {
      public FlowDocumentViewer()
      {
          this.SetValue(ScrollViewer.CanContentScrollProperty, false);
          this.SetValue(ScrollViewer.VerticalScrollBarVisibilityProperty, ScrollBarVisibility.Hidden);
          this.Padding = new Thickness(-17);
          this.Document = new FlowDocument();
      }
  
      protected override void OnMouseWheel(MouseWheelEventArgs e)
      {
          e.Handled = false;
      }
  
      public string Text
      {
          get { return (string)GetValue(TextProperty); }
          set { SetValue(TextProperty, value); }
      }
  
      public static readonly DependencyProperty TextProperty =
          DependencyProperty.Register("Text", typeof(string), typeof(FlowDocumentViewer), new UIPropertyMetadata(string.Empty, TextChangedHandler));
  
      private static void TextChangedHandler(DependencyObject d, DependencyPropertyChangedEventArgs e)
      {
          if (e.NewValue.Equals(string.Empty))
              return;
          FlowDocumentViewer fdv = (FlowDocumentViewer)d;
          fdv.Document.Blocks.Clear();
  
          using (MemoryStream stream = new MemoryStream(UTF8Encoding.UTF8.GetBytes(e.NewValue.ToString())))
          {
              Section content = XamlReader.Load(stream) as Section;
              fdv.Document.Blocks.Add(content);
          }
      }
  }
  </code></pre>