title: The parameter is incorrect error with stackpanel
body: <p>So I am working on a windows phone app, and I am trying to move elements between two stackpanels (which are basically the two main screens of my app).</p>
  
  <p>I have a pivot item which looks like this:</p>
  
  <pre><code>&lt;controls:Pivot Title="MY APPLICATION"&gt;
  &lt;!--Pivot item one--&gt;
      &lt;controls:PivotItem Header="All Tokens"&gt;
          &lt;ListBox x:Name="AllTokenListBox" Margin="0,0,0,0"&gt;
              &lt;StackPanel x:Name="AllTokenStack"&gt;&lt;/StackPanel&gt;
          &lt;/ListBox&gt;
      &lt;/controls:PivotItem&gt;
      &lt;!--Pivot item two--&gt;
      &lt;controls:PivotItem Header="My Tokens"&gt;
          &lt;ListBox x:Name="MyTokenListBox" Margin="0,0,0,0"&gt;
              &lt;StackPanel x:Name="myTokenStack"&gt;&lt;/StackPanel&gt;
          &lt;/ListBox&gt;
      &lt;/controls:PivotItem&gt;
  &lt;/controls:Pivot&gt;
  </code></pre>
  
  <p>When an item in the AllTokenStack is double tapped, I want to move it over to the myTokenStack. When I do that, the program crashes and says "The parameter is incorrect".
  It only does this if I am NOT in debugging mode (so if the phone is unplugged from the computer and I try to run the app). If it is in debugging mode, it works fine.</p>
  
  <p>Here is the code I am using to transfer the object over:</p>
  
  <pre><code>private void container_Tap(object sender, GestureEventArgs e) {
      if (AllTokenContainer.Children.Contains(this)) {
         AllTokenContainer.Children.Remove(this);
         MyTokenContainer.Children.Add(this);      
      }
  }
  </code></pre>
  
  <p>Does anyone know how to resolve this strange bug? </p>
  
  <p><strong>EDIT</strong>
  Just to make it clear. The C# code is inside a class which I called Token. The Token class is a user control. It is that control which the user taps to trigger the event. Is this the wrong way to do it?</p>
  
  <p>Stacktrace from the exception:</p>
  
  <pre><code>   at MS.Internal.XcpImports.CheckHResult(UInt32 hr)
     at MS.Internal.XcpImports.Collection_AddValue[T](PresentationFrameworkCollection`1 collection, CValue value)
     at MS.Internal.XcpImports.Collection_AddDependencyObject[T](PresentationFrameworkCollection`1 collection, DependencyObject value)
     at System.Windows.PresentationFrameworkCollection`1.AddDependencyObject(DependencyObject value)
     at System.Windows.Controls.UIElementCollection.AddInternal(UIElement value)
     at System.Windows.PresentationFrameworkCollection`1.Add(UIElement value)
     at MTG_Token_Tracker.TokenGraphic.container_Tap(Object sender, GestureEventArgs e)
     at MS.Internal.CoreInvokeHandler.InvokeEventHandler(Int32 typeIndex, Delegate handlerDelegate, Object sender, Object args)
     at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32 actualArgsTypeIndex, String eventName)
  </code></pre>