title: Size WPF Browser to its HTML-Content
body: <p>I want to show my Flair in a WPF <code>Browser</code> Control and size it to the smallest size possible.</p>
  
  <p><strong>XAML:</strong></p>
  
  <pre><code>&lt;Window x:Class="TestProject.MainWindow"
          [...]
          Title="MainWindow" 
          MaxHeight="500" 
          MaxWidth="500"
          Loaded="Window_Loaded"
          SizeToContent="WidthAndHeight" 
          Height="86.453" 
          Width="163.44"&gt;
  &lt;Grid&gt;
      &lt;WebBrowser x:Name="browser"&gt;&lt;/WebBrowser&gt;        
  &lt;/Grid&gt;
  </code></pre>
  
  <p></p>
  
  <p><strong>Here is my Code-Behind:</strong></p>
  
  <pre><code>public partial class MainWindow : Window
  {
      public MainWindow()
      {
          InitializeComponent();
      }
  
      private string CreateHTML()
      {
          StringBuilder builder = new StringBuilder();
          builder.AppendLine("&lt;!DOCTYPE html&gt;");
          builder.AppendLine("&lt;html&gt;");
          builder.AppendLine("&lt;body&gt;");
          builder.AppendLine("&lt;a href=\"http://stackexchange.com/users/5852250\"&gt;");
          builder.AppendLine("&lt;img src=\"http://stackexchange.com/users/flair/5852250.png?theme=dark\" width=\"208\" height=\"58\" alt=\"profile for Felix D. on Stack Exchange, a network of free, community-driven Q&amp;amp;A sites\" title=\"profile for Felix D. on Stack Exchange, a network of free, community-driven Q&amp;amp;A sites\"&gt;");
          builder.AppendLine("&lt;/a&gt;");
          builder.AppendLine("&lt;/body&gt;");
          builder.AppendLine("&lt;html&gt;");
          return builder.ToString();
      }
  
      private void Window_Loaded(object sender, RoutedEventArgs e)
      {
          string htmlString = CreateHTML();            
          browser.NavigateToString(htmlString);            
      }        
  }
  </code></pre>
  
  <p>I want the browser(to behave like <code>SizeToContent="WidthAndHeight"</code> for its content).</p>
  
  <p>I have not found a working solution.</p>
  
  <p>I embedded <code>Microsoft.mshtml</code> and tried to get sth. out of <code>browser.Document</code> but I did not make any progress so far.</p>
  
  <p>Anyone done sth. similar ?</p>