title: How to add controls dynamically to a UserControl through user's XAML, 4.0
body: <p>I want to create a user control that contains a Image and a Conainer that will allow the user to add his/her own controls to the user control dynamically in XAML. I am using VS 2010, .NET 4.0</p>
  
  <p>I have created following code. </p>
  
  <p>UserController.xaml</p>
  
  <pre><code> &lt;Grid DockPanel.Dock="bottom"&gt;      
      &lt;Grid.RowDefinitions&gt;
          &lt;RowDefinition Height="Auto"&gt;&lt;/RowDefinition&gt;
      &lt;/Grid.RowDefinitions&gt;
      &lt;Grid.ColumnDefinitions&gt;
          &lt;ColumnDefinition Width="Auto" /&gt;
          &lt;ColumnDefinition Width="*" /&gt;
      &lt;/Grid.ColumnDefinitions&gt;
      &lt;StackPanel  Height="Auto" Grid.Row="0" Grid.Column="0"&gt;
          &lt;Image /&gt;
      &lt;/StackPanel&gt;
      &lt;Grid&gt;
          &lt;ContentControl Content="{Binding Innercontent}" /&gt;
      &lt;/Grid&gt;
  &lt;/Grid&gt;
  </code></pre>
  
  <p>ModeViewCode, Innercontent is an DependencyProperty property</p>
  
  <pre><code>public static DependencyProperty InnerContentProperty = DependencyProperty.Register("InnerContent", typeof(UIElement), typeof(Footer))
  
  public UIElement InnerContent
      {
          get { return (UIElement)GetValue(InnerContentProperty); }
          set { SetValue(InnerContentProperty, value); }
      }
  </code></pre>
  
  <p>Created a DataTemplate which consumes the usercontrol. </p>
  
  <pre><code> &lt;users:Footer HorizontalAlignment="Stretch" VerticalAlignment="Bottom"&gt;
                  &lt;users:Footer.InnerContent&gt;
                      &lt;StackPanel Orientation="Horizontal" x:Name="tst"&gt;
                         &lt;commoncontrols:Button /&gt;
                      &lt;/StackPanel&gt;
                  &lt;/users:Footer.InnerContent&gt;
              &lt;/users:Footer&gt;
  </code></pre>
  
  <p>when code is complied it gives me following error message. </p>
  
  <p>Error   275 Unknown build error, 'Index (zero based) must be greater than or equal to zero and less than the size of the argument list. Line 2582 Position 23.'  at this line (users:Footer.InnerContent). </p>
  
  <p>Got help from following psot <a href="https://stackoverflow.com/questions/21443397/how-to-add-controls-dynamically-to-a-usercontrol-through-users-xaml">Help</a></p>
  
  <p>Any help will be appreciated.     </p>