title: Cannot add run to a textblock in foreach loop
body: <p>I building a UWP application.
  And what I'm trying to achieve is to show a tweet and if there are any urls in the tweet, have it render as a hyperlink text.
  So what I'm doing is going through the text and finding urls and assigning runs into a textblock and then assigning it to the textblock on the page.</p>
  
  <p>Code behind:</p>
  
  <pre><code>TextBlock block = new TextBlock();
  
          Regex url_regex = new Regex(@"(http:\/\/([\w.]+\/?)\S*)" , RegexOptions.IgnoreCase | RegexOptions.Compiled);
  
          MatchCollection collection = url_regex.Matches(tweet);
  
          int index = 0;
  
          //for test only
          Run r = new Run();
          r.Text = "int";
          block.Inlines.Add(r);
  
          foreach (Match item in collection)
          {
  
              Run run = new Run();
              run.Text = tweet.Substring(index , item.Index);
              //error occurs here.
              block.Inlines.Add(run);
  
              index = item.Index;
  
              run.Text = tweet.Substring(index , item.Length);
              Hyperlink h = new Hyperlink();
              h.Inlines.Add(run);
              block.Inlines.Add(h);
  
              index = item.Index + item.Length;
          }
  
          r.Text = tweet.Substring(index , tweet.Length);
          block.Inlines.Add(r);
  
          blok = block;
  </code></pre>
  
  <p>the Xaml:</p>
  
  <pre><code>&lt;StackPanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"&gt;
      &lt;TextBox Name="input"
                  PlaceholderText="input here" /&gt;
      &lt;TextBlock Name="blok"/&gt;
  &lt;/StackPanel&gt;
  </code></pre>
  
  <p>I don't understand what's going on because the test run adding is working fine because it is outside the foreach loop. Once the run is added to the inlines in a <strong>foreachloop</strong> it throws an error saying that :</p>
  
  <pre><code>System.Runtime.InteropServices.COMException: No installed components were detected.
  
  Element is already the child of another element.
  </code></pre>
  
  <p>There are other questions on the internet on this topic but I didn't get a good solution.</p>