title: WPF RichTextBox bolding of Text From Code Efficiently
body: <p>Im brand new to WPF, so please excuse my ignorance, I have tried googling this issue for about 30 min+ and can't seem to find a simple solution that fits my scenario.</p>
  
  <p>Basically Im making an IRC app that reads a line from the server, I read the nick, and the message. And put a line like :</p>
  
  <pre><code>&lt;Nick&gt; Message typed...
  </code></pre>
  
  <p>I want the <code>&lt;Nick&gt;</code> part in bold. And later on maybe in a colour. Also I saw some examples doing for each loops, but if I have a 1000+ lines and do a foreach loop everytime someone types something will that not be inefficent?</p>
  
  <p>Please advise as to best / easiest approach ... from the c# programming side.</p>
  
  <p>Here is my code :</p>
  
  <pre><code>    private void OnChannelMessage(object sender, IrcEventArgs e)
      {
          if (!txtActivity.Dispatcher.CheckAccess())
          {
              txtActivity.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(delegate()
                    {
                        txtActivity.AppendText(string.Format("&lt;Bold&gt;&lt;{0}:{1}&gt;&lt;/Bold&gt; {2}\n", e.Data.Channel, e.Data.Nick, e.Data.Message));
  
                        //Paragraph p = new Paragraph();
                        //p.Inlines.Add(new Bold(new Run(string.Format("&lt;{0}&gt; ", e.Data.Nick))));
                        //p.Inlines.Add(new Run(string.Format("{0}\n", e.Data.Message)));
                        //txtActivity.Document.Blocks.Add(p); // problem adds a big space between lines.
                    }
              ));
          }
      }
  </code></pre>
  
  <p>XAML:</p>
  
  <pre><code>&lt;Grid&gt;
      &lt;RichTextBox Name="txtActivity" VerticalScrollBarVisibility="Auto" Margin="12,12,12,41" BorderThickness="2" FontFamily="Consolas"&gt;
          &lt;RichTextBox.Resources&gt;
              &lt;Style TargetType="{x:Type Paragraph}"&gt;
                  &lt;Setter Property="Margin" Value="0"/&gt;
              &lt;/Style&gt;
          &lt;/RichTextBox.Resources&gt;
      &lt;/RichTextBox&gt;
      &lt;Button Content="Quit" Height="23" HorizontalAlignment="Left" Margin="628,371,0,0" Name="btnQuit" VerticalAlignment="Top" Width="50" Click="btnQuit_Click" /&gt;
  &lt;/Grid&gt;
  </code></pre>