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

  • SEARCH
  • Home
  • 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 3424808
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T06:31:08+00:00 2026-05-18T06:31:08+00:00

Hi all i have a listbox MainListBox where i add items to dynamically. Now

  • 0

Hi all i have a listbox MainListBox where i add items to dynamically.
Now i want to navigate to DetialsPage.xaml.cs when i choose an item in the listbox.
where i can then display my info about the selected item.

private void SetListBox()
{
    foreach (ToDoItem todo in itemList)
    {
        MainListBox.Items.Add(todo.ToDoName);
    }
}

MainListBox_SelectionChanged (“Generated by visual studio 2010 silverlight for windows 7 phone)

// Handle selection changed on ListBox
private void MainListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
    // If selected index is -1 (no selection) do nothing
    if (MainListBox.SelectedIndex == -1)
        return;

    // Navigate to the new page
    NavigationService.Navigate(new Uri("/DetailsPage.xaml?selectedItem=" + MainListBox.SelectedIndex, UriKind.Relative));

    // Reset selected index to -1 (no selection)
    MainListBox.SelectedIndex = -1;
}

in DetailsPage.xaml.cs is the next method. (“Generated by visual studio 2010 silverlight for windows 7 phone)
I’m aware that the below method does not do what i try.

// When page is navigated to set data context to selected item in list
protected override void OnNavigatedTo(NavigationEventArgs e)
{
    string selectedIndex = "";
    if (NavigationContext.QueryString.TryGetValue("selectedItem", out selectedIndex))
    {
        int index = int.Parse(selectedIndex);
        DataContext = App.ViewModel.Items[index];
    }
}

I would like to access the selectedIndex and call my methods of my object that is in the MainListbox
so Basicly:
Mainlistbox => select item => send that item to details page => details page access the item and call methods on the item (object)

I’m sure this is a basic question tough it seems hard to find any specifics on it. i would like to add that this is my first windows phone 7 app.

  • 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-18T06:31:08+00:00Added an answer on May 18, 2026 at 6:31 am

    There are many ways you can pass an object from page to page:

    1. serialize and deserialize like Dennis said, but this, although feasable, is not practical, unless you want to save the object in isolated storage and retrieve it later.

    2. Place an object in the App.cs class, which is accessible to all pages. Set your object in the master page, retrieve it from the Details page.

    Code to put in App.cs: MyObject selectedObject;

    Code to put in MasterPage.cs: application.selectedObject = MainListBox.selectedItem;

    Code to put in DetailsPage.cs: MyObject selectedObject = application.seletedObject;

    1. You can set the Object in the DataContext of your LayoutRoot, but i don’t have the code for that on top of my head.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I make a silverlight listbox have all items be the same size
I have a listbox containing all the items and a second listbox that will
I have a listbox, with items that can be in some kind of group
I have a asp:ListBox wrapped inside an asp:UpdatePanel. The list box contains all the
I have a ListBox with horizontal scrolling, and each item consists of a two
So I have a Listbox: <ListBox Grid.Row=0 Grid.Column=1 Grid.RowSpan=2> //<----Item's Data Source Method Call
I have a Listbox where all cells are editable. While the user is typing
I have two listbox in windows Form c#, the first one has all valid
I have a Listbox. Each item has Context menu.IfI simply hold on item and
I'm sure we all have received the wonderfully vague Object reference not set to

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.