title: Loading UserControl to ItemsControl with MVVM
body: <p>I have a UserControl which I would like to load multiple times on my MainWindow.
  For this I use an <code>ItemsControl</code>:</p>
  
  <pre><code>    &lt;ItemsControl Grid.Row="1"
                ItemsSource="{Binding FtpControlList, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"&gt;
    &lt;ItemsControl.ItemsPanel&gt;
      &lt;ItemsPanelTemplate&gt;
        &lt;WrapPanel Orientation="Horizontal"
                   IsItemsHost="True" /&gt;
      &lt;/ItemsPanelTemplate&gt;
    &lt;/ItemsControl.ItemsPanel&gt;
    &lt;ItemsControl.ItemTemplate&gt;
      &lt;DataTemplate DataType="{x:Type my:BackUpControl}"&gt;
        &lt;my:BackUpControl Margin="5"
                          Width="500" /&gt;
      &lt;/DataTemplate&gt;
    &lt;/ItemsControl.ItemTemplate&gt;
  &lt;/ItemsControl&gt;
  </code></pre>
  
  <p>My UserControl is bound by a ViewModel. My MainWindow also has a ViewModel.
  In the MainWindowViewModel I have an OberservableCollection dependency property which houlds a list of my UserControlViewModels. In the constructor of the MainWindowViewModel I add some UserControlViewModels to the List.</p>
  
  <pre><code>    public MainWindowViewModel()
  {
    FtpControlList = new ObservableCollection&lt;BackUpControlViewModel&gt;();
    FtpControlList.Add(new BackUpControlViewModel("View 1"));
    FtpControlList.Add(new BackUpControlViewModel("View 2"));
    FtpControlList.Add(new BackUpControlViewModel("View 3"));
  }
  
  public static readonly DependencyProperty FtpControlListProperty = DependencyProperty.Register("FtpControlList", typeof(ObservableCollection&lt;BackUpControlViewModel&gt;), typeof(MainWindowViewModel));
  public ObservableCollection&lt;BackUpControlViewModel&gt; FtpControlList
  {
    get { return (ObservableCollection&lt;BackUpControlViewModel&gt;)GetValue(FtpControlListProperty); }
    set { SetValue(FtpControlListProperty, value); }
  }
  </code></pre>
  
  <p>Now for some reason it loads 3 times an empty usercontrol and NOT the ones in the FtpControlList property withe the property set to 'View 1, View 2 and View 3'. How can I make sure that the UserControls from the list are loaded and not empty ones?</p>
  
  <p>Part of the UserControlViewModel:</p>
  
  <pre><code>    // part of the UserControl Viewmodel
      public BackUpControlViewModel()
  {
  }
  
  public BackUpControlViewModel(string header)
  {
    GroupBoxHeader = header;
  }
  
      #region Dependency Properties
  public static readonly DependencyProperty GroupBoxHeaderProperty = DependencyProperty.Register("GroupBoxHeader", typeof(string), typeof(BackUpControlViewModel), new UIPropertyMetadata("empty"));
  public string GroupBoxHeader
  {
    get { return (string)GetValue(GroupBoxHeaderProperty); }
    set { SetValue(GroupBoxHeaderProperty, value); }
  }
  
  public static readonly DependencyProperty FtpUrlProperty = DependencyProperty.Register("FtpUrl", typeof(string), typeof(BackUpControlViewModel), new UIPropertyMetadata("ftpurl"));
  public string FtpUrl
  {
    get { return (string)GetValue(FtpUrlProperty); }
    set { SetValue(FtpUrlProperty, value); }
  }
  
  public static readonly DependencyProperty FtpUserProperty = DependencyProperty.Register("FtpUser", typeof(string), typeof(BackUpControlViewModel), new UIPropertyMetadata("ftpUser"));
  public string FtpUser
  {
    get { return (string)GetValue(FtpUserProperty); }
    set { SetValue(FtpUserProperty, value); }
  }
  #endregion
  </code></pre>
  
  <p>It will probably be something stupid but I can't seem to find it.
  The datacontext for MainWindow and the UserControl are bound to it's Viewmodel.</p>
  
  <p>EDIT: BackupControl datacontext set to BackupControlViewModel (to answer Rachel's question)</p>
  
  <pre><code>   public partial class BackUpControl : UserControl
    {
      public BackUpControl()
      {
        InitializeComponent();
        this.DataContext = new BackUpControlViewModel();
      }
    }
  </code></pre>