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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T21:47:15+00:00 2026-05-23T21:47:15+00:00

So I am using C# with WPF. I have a list box where I

  • 0

So I am using C# with WPF. I have a list box where I generate 100 Music Stations, but I want to select one of them while there are generating, but I can’t, only when they are done generating.

I am using this code to center the selected item (taken from msdn blog):

FrameworkElement container = listRadioItems.ItemContainerGenerator.ContainerFromItem(fixedItem) as FrameworkElement;

            if (null != container)
            {
                if (ScrollViewer.GetCanContentScroll(listBox))
                {
                    IScrollInfo scrollInfo = VisualTreeHelper.GetParent(container) as IScrollInfo;
                    if (null != scrollInfo)
                    {
                        StackPanel stackPanel = scrollInfo as StackPanel;
                        VirtualizingStackPanel virtualizingStackpanel = scrollInfo as VirtualizingStackPanel;

                        int index = listBox.ItemContainerGenerator.IndexFromContainer(container);

                        if (((null != stackPanel) && (Orientation.Horizontal == stackPanel.Orientation)) || ((null != virtualizingStackpanel) && (Orientation.Horizontal == virtualizingStackpanel.Orientation)))
                        {
                            scrollInfo.SetHorizontalOffset(index - Math.Floor(scrollInfo.ViewportWidth / 2));
                        }
                        else
                        {
                            scrollInfo.SetVerticalOffset(index - Math.Floor(scrollInfo.ViewportHeight / 2));
                        }
                    }
                }

                else
                {
                    Rect rect = new Rect(new Point(), container.RenderSize);

                    FrameworkElement constrainingParent = container;
                    do
                    {
                        constrainingParent = VisualTreeHelper.GetParent(constrainingParent) as FrameworkElement;
                    } while ((null != constrainingParent) && (listBox != constrainingParent) && !(constrainingParent is ScrollContentPresenter));

                    if (null != constrainingParent)
                    {
                        rect.Inflate(Math.Max((constrainingParent.ActualWidth - rect.Width) / 2, 0), Math.Max((constrainingParent.ActualHeight - rect.Height) / 2, 0));
                    }

                    container.BringIntoView(rect);
                }
            }

Using some other codes instead of this, I can select the items, still hard(I click on the item and wait a few seconds until it will be pressed, not the one I choose, but some other from that position, hope to make myself clear).

So it is something wrong with this code that prevents me to select an item before it reaches 100 ? Or is there a programming way to fix my problem ?

Hope you guys understand my problem. 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-23T21:47:15+00:00Added an answer on May 23, 2026 at 9:47 pm

    So it is something wrong with this code that prevents me to select an
    item before it reaches 100 ? Or is there a programming way to fix my
    problem ?

    The reason your unable to select an item is because the method your using to add items to the list is blocking that behavior. This is the reason your other method allows you to select an item ( the wait is from the blocking behavior ) but the item selected is the same item you selected while the list was being created. In other words the item was in slot 50 but the item you really want was moved down to slot 60.

    Since you didn’t post how your adding items to the ListBox this is the best I can do.

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

Sidebar

Related Questions

Using WPF, I have a TreeView control that I want to set its ItemTemplate
I have a 16 bit grayscale image that I want to display using WPF
I have a WPF application and am using the WPF toolkit autocomplete box in
I want to show multiple columns in the list box. I have referred the
I have a WPF application that has a list box of images. Right now
I have been using WPF for a few years now and don't have any
Anyone using WPF for real LOB applications? We have all seen the clever demos
I have a situation where I am using wpf data binding and validation using
I'm using WPF with .NET 3.0. I have a relatively simple DataTemplate defined as
So, I have this desktop app built using WPF and C#. It's basically 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.