title: Custom Html TextBlock in DataGrid
body: <p>I'd like to display a kind of rich text in (readonly) DataGrid. It should include basic styling (bold, italic) and hyperlinks, i.e. grid cell should take something like:
      <pre>&lt;a>Here&lt;/a> and &lt;a>also here&lt;/a> you can find &lt;b>stuff&lt;b></pre>
  and render it as if it were html. Of course, data is coming from database so everything should be bindable.</p>
  
  <p>After trying to patch-up appropriate template or style, I've given up and tried to make custom control. Control was fairly simple:</p>
  
  <pre><code>public class SmartTextBlock : TextBlock
  {
      public static readonly DependencyProperty HtmlProperty = DependencyProperty.Register("Html", typeof(string), typeof(SmartTextBlock), new UIPropertyMetadata(null, new PropertyChangedCallback(OnHtmlChanged)));
  
      public string Html
      {
          get { return GetValue(HtmlProperty) as string; }
          set { SetValue(HtmlProperty, value); }
      }
  
      static void OnHtmlChanged(DependencyObject target, DependencyPropertyChangedEventArgs e) {
          SmartTextBlock control = target as SmartTextBlock;
          control.createParts(e.NewValue as string);
      }
  
      void createParts(string text) {
          Inlines.Clear();
          /* parse text and add some Inlines */
      }
  }
  </code></pre>
  
  <p>That went well and control is displaying nicely. It was smoothly added to grid as:</p>
  
  <pre><code>&lt;DataGridTemplateColumn Width="*" Header="Line"&gt;
      &lt;DataGridTemplateColumn.CellTemplate&gt;
          &lt;DataTemplate&gt;
              &lt;controls:SmartTextBlock Html="{Binding Path=Html}" TextWrapping="Wrap" /&gt;
          &lt;/DataTemplate&gt;
      &lt;/DataGridTemplateColumn.CellTemplate&gt;
  &lt;/DataGridTemplateColumn&gt;
  </code></pre>
  
  <p>The problem is when I try to resize or scroll grid. Then whole window starts to blink and application hangs! This doesn't happen every time but if you try long enough it would start for sure.</p>
  
  <p>Any ideas what might be cause of this, which obvious mistake am I overlooking?</p>