title: How to add UserControl to a Panel on a WPF Window
body: <p>I think I'm missing something that should be obvious here, but I'm drawing a blank on this one.</p>
  
  <p>I've built a very primitive UserControl containing nothing more than a <code>TextBox</code> to use as a log window:</p>
  
  <pre><code>&lt;UserControl x:Class="My.LoggerControl"
               xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
               xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
               xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
               xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
               x:Name="LoggerView"&gt;
      &lt;Grid x:Name="LayoutRoot"&gt;
          &lt;TextBox x:Name="LogWindow" AcceptsReturn="True"/&gt;
      &lt;/Grid&gt;
  &lt;/UserControl&gt;
  </code></pre>
  
  <p>I don't expect that to be the best way to do it, but it should be good enough for a prototype.</p>
  
  <p>The code-behind is similarly simple:</p>
  
  <pre><code>public partial class LoggerControl : UserControl, ILogger
  {
      public LoggerControl()
      {
          InitializeComponent();
      }
  
      private LogLevel level = LogLevel.Warning;
  
      #region ILogger
  
      public LogLevel Level
      {
          get { return level; }
          set { level = value; }
      }
  
      public void OnError(string s)
      {
          if (level &gt;= LogLevel.Error)
              LogWindow.AppendText("ERROR:::" + s + "\n");
      }
  
      // ...
      #endregion
  }
  </code></pre>
  
  <p>The thing I can't figure out is how to add this control to my <code>MainWindow.xaml</code>. Simplifying, lets say my window looks like this:</p>
  
  <pre><code>&lt;Window x:Class="My.MainWindow"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:local="clr-namespace:My"
      Title="Test" Height="350" Width="525"&gt;
      &lt;Grid&gt;
          &lt;local:LoggerControl x:Name="LogView" /&gt;
      &lt;/Grid&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p>Even with something so simple, the Designer in Visual Studio 2010 can't load the main window. The error given is:</p>
  
  <blockquote>
    <p>A value of type 'LoggerControl' cannot be added to a collectionor dictionary of type 'UIElementCollection'.</p>
  </blockquote>
  
  <p>This error message has only one unrelated hit in the major search engines (plus duplicates) so I haven't found any useful help. Microsoft's own documentation seems to imply that this should work.</p>
  
  <p>Any idea how to solve this?</p>