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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T21:43:23+00:00 2026-06-05T21:43:23+00:00

I have a ListBox with items that fill TextBox es. How do I identify

  • 0

I have a ListBox with items that fill TextBoxes. How do I identify the text string that is selected when a selection is made from the ListBox. Here’s my XAML code for the ListBox:

<StackPanel x:Name="InputPanel" Orientation="Horizontal" HorizontalAlignment="Left">
    <StackPanel>
        <TextBlock Text="Input" Style="{StaticResource H2Style}"/>
        <TextBlock Text="Select Scenario:" Style="{StaticResource H3Style}"/>
        <ListBox x:Name="ScenarioList" Margin="0,0,20,0" HorizontalAlignment="Left" SelectionChanged="ScenarioList_SelectionChanged">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding Name}"/>
                </DataTemplate>
            </ListBox.ItemTemplate>
            <ListBoxItem x:Name="Scenario1">
                <TextBlock Style="{StaticResource ListBoxTextStyle}" Text="1) Pick a single photo" />
            </ListBoxItem>
            <ListBoxItem x:Name="Scenario2">
                <TextBlock Style="{StaticResource ListBoxTextStyle}" Text="2) Pick multiple files" />
            </ListBoxItem>
            <ListBoxItem x:Name="Scenario3">
                <TextBlock Style="{StaticResource ListBoxTextStyle}" Text="3) Pick a folder" />
            </ListBoxItem>
            <ListBoxItem x:Name="Scenario4">
                <TextBlock Style="{StaticResource ListBoxTextStyle}" Text="4) Save a file" />
            </ListBoxItem>
        </ListBox>
    </StackPanel>

I have tried all kinds of things in my selection_changed method. Here’s the latest one:

object selectedItem = ScenarioList.SelectedItem;
ListBoxItem selected = this.ScenarioList.ItemContainerGenerator.ContainerFromItem(this.ScenarioList.SelectedItem) as ListBoxItem;
string tempStr = selected.Content.ToString();
  • 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-05T21:43:25+00:00Added an answer on June 5, 2026 at 9:43 pm
    ListBoxItem listBox_Item = listBox.SelectedItem as ListBoxItem;
    MessageBox.Show("You have selected " + listBox_Item.Content.ToString());
    

    or You can try this one on Selection changed event

     private void ScenarioList_SelectionChanged(object sender, SelectionChangedEventArgs e) 
      {
            if (((ListBox)sender).SelectedItem != null)
            MessageBox.Show("You have selected " + (ListBox)sender).SelectedItem);
      }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a ListBox that can have multiple items selected at once. I have
I have a listbox where I want to copy and paste items within that
I have a listbox that displays Shipment Items (custom class) that are formatted using
I have a ListBox in Silverlight that has a list of items inside. Each
I have a data bound listbox that lists names of items, I am now
I currently have a listbox that has its selected item bound to a property
I have a listbox with a datatemplate for the items. The problem is that
I have a ListBox that contains a number of User items that are DataTemplate
I am trying to build a ListBox with items that have edit states. I
I have a ListBox that has a bunch of items in it. However, I

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.