title: Naming user controls without default constructors in XAML
body: <p>I have a user control without a parameterless constructor; let's call it <code>WithoutDefaultConstructor</code>. I want to insert a <code>WithoutDefaultConstructor</code> called <code>myControl</code> into the XAML code of another control (which is called <code>MainWindow</code>). However, I get this compiler error:</p>
  
  <blockquote>
    <p>The type 'WithoutDefaultConstructor'
    cannot have a Name attribute. Value
    types and types without a default
    constructor can be used as items
    within a ResourceDictionary.</p>
  </blockquote>
  
  <p>How do I fix this without adding a parameterless constructor to <code>WithoutDefaultConstructor</code>?</p>
  
  <p>Here are the contents of <code>MainWindow.xaml</code>:    </p>
  
  <pre><code>&lt;Window x:Class="WpfApplication1.MainWindow"
   xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
   xmlns:WpfApplication1="clr-namespace:WpfApplication1" Title="MainWindow" 
   Height="350" Width="525"&gt;
      &lt;WpfApplication1:WithoutDefaultConstructor Name="myControl"&gt;
      &lt;/WpfApplication1:WithoutDefaultConstructor&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p>Here are the contents of <code>WithoutDefaultConstructor.xaml.cs</code>:</p>
  
  
  
  <pre class="lang-cs prettyprint-override"><code>using System.Windows.Controls;
  
  namespace WpfApplication1
  {
      public partial class WithoutDefaultConstructor : UserControl
      {
          private int I_really_need_to_initialize_this_int;
  
          public WithoutDefaultConstructor(int i)
          {
              InitializeComponent();
              I_really_need_to_initialize_this_int = i;
          }
      }
  }
  </code></pre>