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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T01:58:07+00:00 2026-05-13T01:58:07+00:00

I am new to WPF, so I thought this was simple. I have a

  • 0

I am new to WPF, so I thought this was simple. I have a form with a listbox and a button. In the click handler for the button I do something iteratively that generates strings, which I want to put in the listbox as I get them. The xaml for the list box is like

    <ListBox Height="87" Margin="12,0,12,10" Name="lbxProgress" VerticalAlignment="Bottom">
        <ListBox.BindingGroup>
            <BindingGroup Name="{x:Null}" NotifyOnValidationError="False" />
        </ListBox.BindingGroup>
    </ListBox>

and the click handler is like

private void btn_Click(object sender, RoutedEventArgs e)  
{  
  List<String> lstrFiles= new List<String>(System.IO.Directory.GetFiles   ("C:\\temp", "*.tmp");  

  foreach(string strFile in lstrFiles)  
    lbxProgress.Items.Add(strFile);  
}  

Pretty straightforward. Since my real operation is lengthy, I want the listbox to update as I do each one – how do I get the box to dynamically update on each addition?

  • 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-13T01:58:07+00:00Added an answer on May 13, 2026 at 1:58 am

    Create an ObservableCollection<string> and set your ListBox.ItemsSource to that collection. Because the collection is observable, the ListBox will update as its contents change.

    However, if your real operation is blocking the UI thread, this may prevent WPF from updating the UI until the operation completes (because the WPF data binding infrastructure doesn’t get a chance to run). So you may need to run your lengthy operation on a background thread. In this case, you will not be able to update the ObservableCollection from the background thread due to WPF cross-threading restrictions (you can update properties, but not collections). To get around this, use Dispatcher.BeginInvoke() to update the collection on the UI thread while continuing your operation on the background thread.

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

Sidebar

Related Questions

I am new to WPF. I have a ListBox that has its ItemSource set
I'm new to both C# and WPF. I've written a simple program. I have
I'm trying to create a simple global exception handler in a WPF application that
I ran into this interesting issue today. I have a button on a wpf
New to wpf and through a learning curve. I have a userControl with a
being new to WPF this is a complex problem for me. What i want
I'm new to WPF. I have a WPF Window with a bunch of Labels
I have a WPF application where I'm trying to create a diagnostics panel that's
We have an object that derives from DependencyObject, and implements some DependencyProperties. Basically something
I'm fairly new to wpf and this website. Please give me some mercy if

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.