Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7989821
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T12:51:10+00:00 2026-06-04T12:51:10+00:00

So I am working on a windows phone app, and I am trying to

  • 0

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).

I have a pivot item which looks like this:

<controls:Pivot Title="MY APPLICATION">
<!--Pivot item one-->
    <controls:PivotItem Header="All Tokens">
        <ListBox x:Name="AllTokenListBox" Margin="0,0,0,0">
            <StackPanel x:Name="AllTokenStack"></StackPanel>
        </ListBox>
    </controls:PivotItem>
    <!--Pivot item two-->
    <controls:PivotItem Header="My Tokens">
        <ListBox x:Name="MyTokenListBox" Margin="0,0,0,0">
            <StackPanel x:Name="myTokenStack"></StackPanel>
        </ListBox>
    </controls:PivotItem>
</controls:Pivot>

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.

Here is the code I am using to transfer the object over:

private void container_Tap(object sender, GestureEventArgs e) {
    if (AllTokenContainer.Children.Contains(this)) {
       AllTokenContainer.Children.Remove(this);
       MyTokenContainer.Children.Add(this);      
    }
}

Does anyone know how to resolve this strange bug?

EDIT
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?

Stacktrace from the exception:

   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)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T12:51:11+00:00Added an answer on June 4, 2026 at 12:51 pm

    Rather than using UserControls, I would try to use databinding, with ObservableCollection‘s of token classes in the back end. Moving things around becomes a little easier when the GUI part gets taken care of by the binding.

    For an example of how to do this, I created a Windows Phone project using the “Windows Phone Pivot Application” template to use as a base, and named it “TokenAnswer” (if you do this and paste in the code below, you should have a working example).

    To MainPage.xaml, I added the DoubleTap event to the first list’s item template, and set the SecondListBox binding to “Items2”. I also set Tag={Binding}, which sets the Tag variable to the ItemViewModel behind the GUI item (this is done so I can access the item tapped, there are other ways to do this, but this one is easy enough for this example).

    <phone:PhoneApplicationPage 
    x:Class="TokenAnswer.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:controls="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768" 
    d:DataContext="{d:DesignData SampleData/MainViewModelSampleData.xaml}"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait"  Orientation="Portrait"
    shell:SystemTray.IsVisible="True">
    
    <!--LayoutRoot is the root grid where all page content is placed-->
    <Grid x:Name="LayoutRoot" Background="Transparent">
        <!--Pivot Control-->
        <controls:Pivot Title="MY APPLICATION">
            <!--Pivot item one-->
            <controls:PivotItem Header="first">
                <!--Double line list with text wrapping-->
                <ListBox x:Name="FirstListBox" Margin="0,0,-12,0" ItemsSource="{Binding Items}">
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                          <StackPanel DoubleTap="Token_DoubleTap" Tag="{Binding}" Margin="0,0,0,17" Width="432" Height="78">
                              <TextBlock Text="{Binding LineOne}" TextWrapping="Wrap" Style="{StaticResource PhoneTextExtraLargeStyle}"/>
                              <TextBlock Text="{Binding LineTwo}" TextWrapping="Wrap" Margin="12,-6,12,0" Style="{StaticResource PhoneTextSubtleStyle}"/>
                          </StackPanel>
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>
            </controls:PivotItem>
    
            <!--Pivot item two-->
            <controls:PivotItem Header="second"> 
                <!--Triple line list no text wrapping-->
                    <ListBox x:Name="SecondListBox" Margin="0,0,-12,0" ItemsSource="{Binding Items2}">
                        <ListBox.ItemTemplate>
                            <DataTemplate>
                                <StackPanel Margin="0,0,0,17">
                                    <TextBlock Text="{Binding LineOne}" TextWrapping="NoWrap" Margin="12,0,0,0" Style="{StaticResource PhoneTextExtraLargeStyle}"/>
                                    <TextBlock Text="{Binding LineThree}" TextWrapping="NoWrap" Margin="12,-6,0,0" Style="{StaticResource PhoneTextSubtleStyle}"/>
                                </StackPanel>
                            </DataTemplate>
                        </ListBox.ItemTemplate>
                    </ListBox>
            </controls:PivotItem>
        </controls:Pivot>
    </Grid>
    
    </phone:PhoneApplicationPage>
    

    In the MainViewModel.cs, I added a second collection (“Items2”) and initialized it in the constructor, this collection is for the second listbox:

    public MainViewModel()
        {
            this.Items = new ObservableCollection<ItemViewModel>();
            this.Items2 = new ObservableCollection<ItemViewModel>();
        }
    
        /// <summary>
        /// A collection for ItemViewModel objects.
        /// </summary>
        public ObservableCollection<ItemViewModel> Items { get; private set; }
        public ObservableCollection<ItemViewModel> Items2 { get; private set; }
    

    Finally, in MainPage.xaml.cs, I added the codebehind for the event handler, to remove the item from the first collection, and add it to the second.

    private void Token_DoubleTap(object sender, GestureEventArgs e)
        {
            var token = (sender as StackPanel).Tag as ItemViewModel;
            App.ViewModel.Items.Remove(token);
            App.ViewModel.Items2.Add(token);
        }
    

    Hopefully you can use this as a guide to help your current project!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on an app on Windows Phone and trying to get data
I'm working on an App on the windows phone which is very sound, heavy,
I'm working windows phone 7 app which loads an image inside a HyperlinkButton. This
I am working on a Windows Phone 7 app, and trying to change some
I'm working on an app in C# (Windows-Phone-7), and I'm trying to do something
I'm working on my windows-phone app which uses some simple data binding. I've already
I'm currently working on a Twitter app for Windows Phone, in which – via
I#m working on a Windows Phone App in Visual Studio, which displays a Webbrowser
Hi I am working in windows 7 phone based app using silverlight. I have
I'm trying to implement a Push Notification based app on Windows Phone. I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.