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 7627605
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:28:54+00:00 2026-05-31T05:28:54+00:00

I am building a WP7 app that consist on one listbox in the first

  • 0

I am building a WP7 app that consist on one listbox in the first page to show the id of several task and a detail page to show the details for each task (selected).

I need to pass the task id from the first page to the second one. I know that it is carried out by SelectionChanged event of the listbox.

This is my XAML code:

<phone:PhoneApplicationPage 
    x:Class="TaskListAlpha03.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: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="696"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait" Orientation="Portrait"
    shell:SystemTray.IsVisible="True"    
    xmlns:controls="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls">

    <phone:PhoneApplicationPage.Resources>
        <DataTemplate x:Key="TaskListListBoxTemplate">            
            <StackPanel Orientation="Vertical" Margin="0,0,0,20">                
                <TextBlock Text="{Binding Crm_object_id}" FontSize="32" FontFamily="Segoe WP Bold" Foreground="Gray"/>
                <!--<TextBlock Text="{Binding Comment}" Margin="10,0,0,0"/>              -->
            </StackPanel>            
        </DataTemplate>
    </phone:PhoneApplicationPage.Resources>

        <!--LayoutRoot is the root grid where all page content is placed-->
    <Grid x:Name="LayoutRoot" Background="Transparent">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <!--TitlePanel contains the name of the application and page title-->
        <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,40">
            <TextBlock x:Name="ApplicationTitle" Text="TASK LIST ALPHA" Style="{StaticResource PhoneTextNormalStyle}"/>
            <TextBlock x:Name="PageTitle" Text="tasks" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
        </StackPanel>

        <!--ContentPanel - place additional content here-->
        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
            <ListBox 
                        x:Name="allTaskListTasksListBox" 
                        ItemsSource="{Binding AllTaskListTasks}" 
                        ItemTemplate="{StaticResource TaskListListBoxTemplate}"
                        SelectionChanged="allTaskListTasksListBox_SelectionChanged" />
        </Grid>
    </Grid>


</phone:PhoneApplicationPage>

And this is the cs code:

    private void allTaskListTasksListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {            
        ListBoxItem lbi = ((sender as ListBox).SelectedItem as ListBoxItem);
        NavigationService.Navigate(new Uri("/View/Details.xaml?msg=" + lbi.Content.ToString(), UriKind.RelativeOrAbsolute));
    }

In the second page I have this sample code to check if it works:

protected override void OnNavigatedTo
        (System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            string msg = "";
            if (NavigationContext.QueryString.TryGetValue("msg", out msg))
                PageTitle.Text = msg;
        }

When I execute the application I have a “NullReferenceException”.

Sorry for my english :S and thanks.

  • 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-05-31T05:28:55+00:00Added an answer on May 31, 2026 at 5:28 am

    A couple of points here…
    1) I would use a Tap event on the item rather than a selection changed event. It helps prevent accidental navigation.
    2) If you do use the selectionchanged event, try the following code to get your item. Your current code will attempt to fire if an items is de-selected in the list.

    private void allTaskListTasksListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {   
        if(e.AddedItems.Count > 0) // the items that were added to the "selected" collection
        {
            var mySelectedItem = e.AddedItems[0] as myItemType;
            if(null != mySelectedItem) // prevents errors if casting fails
            {
                NavigationService.Navigate(
                   new Uri("/View/Details.xaml?msg=" + mySelectedItem.Crm_object_id, 
                           UriKind.RelativeOrAbsolute)
                );
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm building a wp7 Silverlight app. I need a list that is able to
I'm building this WP7 app that uses a video game API to get the
I'm building a BattleShip game for WP7 that has board with 250 cells. I
Building my first WP theme and I quickly realized that I need to remove
We are building a WP7 mobile game that will allow players to purchase game
Building my first web app using Yii and wondering if it is best to
I'm building a WP7 app, and I'm now at the point of handling the
I am working on a localized wp7 app and in the process of building
Building a WP7 app using MVVM light for my view models. I'm using the
This is kind of weird. I'm building a page based off of WP7 and

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.