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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:03:16+00:00 2026-05-22T18:03:16+00:00

I am only displaying the selected element of a ListBox ( yeah I know

  • 0

I am only displaying the selected element of a ListBox (yeah I know) … And I am trying to understand why if I have a single ListBox.ItemTemplate with a single child of ListBoxItem, I have to traverse 2 ListBoxItems to access the element named “thisListBoxItem”? It seems like there should only be one visual ListBoxItem element.

my XAML

<ListBox Name="cjisDisplayItemListBox" SelectionChanged="cjisDisplayItemListBox_SelectionChanged_1">
  <ListBox.ItemTemplate >
    <DataTemplate>
      <ListBoxItem Name="thisListBoxItem" Visibility="Collapsed">
      <!-- some TextBlocks with bindings here --> 
      </ListBoxItem>
    </DataTemplate>
  </ListBox.ItemTemplate>
</ListBox>

//First I cast SelectedItem to a ListBoxItem (myListBoxItem)
// then I have to descend to a lower ListBoxItem via the FindName property..

private void cjisDisplayItemListBox_SelectionChanged_1(object sender, SelectionChangedEventArgs e)
                    {
                        ListBox lb = sender as ListBox;
                        object item = lb.SelectedItem as object;
                        ListBoxItem myListBoxItem = (ListBoxItem)(lb.ItemContainerGenerator.ContainerFromItem(item));
                        ContentPresenter myContentPresenter = FindVisualChild<ContentPresenter>(myListBoxItem);
                        if (myContentPresenter == null) return;
                        DataTemplate myDataTemplate = myContentPresenter.ContentTemplate;
                        ListBoxItem temp = (ListBoxItem)myDataTemplate.FindName("thisListBoxItem", myContentPresenter);
                        if (myListBoxItem.IsSelected) temp.Visibility = System.Windows.Visibility.Visible;
                    }
  • 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-22T18:03:17+00:00Added an answer on May 22, 2026 at 6:03 pm

    What you have is incorrect. The ListBox will automatically wrap the items in instances of ListBoxItem. In your case, you are displaying a ListBoxItem (from your DataTemplate) in the one that is automatically created for you.

    You should use ItemContainerStyle to set properties on the automatically created ListBoxItem.

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

Sidebar

Related Questions

I'm trying to implement scrolling functionality in a textBox, so that I'm only displaying
i have a listbox and i would want to display a label displaying: scrolling
I have a list field displaying text, and I want only the text to
This only occurs in Internet Explorer. I have a ListBox which is in an
I need some help revising this. It keeps only displaying 0s as the temp.
The only experience I have so far with a touchscreen interface was one where
I only want a list of files that have been added (not ones that
I have ObservableCollection<Foo> that is bound to an ItemsControl (basically displaying a list). Foo
I have a DataGridViewComboBoxColumn where I'm supposed to display different values than are selected,
I have a single ListView with a DataPager that loads datasource 'A' within an

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.