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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:22:23+00:00 2026-05-23T15:22:23+00:00

I am new to WPF, even though I have tried to read as much

  • 0

I am new to WPF, even though I have tried to read as much as I can, I am newbie in need of the wisdom the WPF sages here.

I have a viewlist with a custom view that display a tileview of linecharts. The user selects an item in a separate listbox, this sets the datasource to be used in the listview. My problem is that the UI freezes while the listivew is generating the view. here is how the layout looks:

((sorry, I am new at the site so I can not post images, yet, here is a link: ScreenShot))

The datasource consist of a class that contains some descriptive properties and a list of a list of datapoints (x,y). The tileview takes the list of a list of datapoints and generates one line chart for each listitem using the list of datapoints to draw the line.

Currently I have a datasource with a list holding 200 items and each item has about 200 datapoints (x,y).

When I select an item in the listbox of the left, I use the SelectionChanged event to set the ItemsSource property my listview with the new dataset. The problem is that the UI freezes until all the charts are generated.

I have been trying different approaches without success. I tried to set the datasource as an asynchronous one:

DataSeries="{Binding IsAsync=True, Path=Data}"

This only helps a tinny tinny bit by releasing the UI before the view is rendered. That means that after changing the datasource it will freeze the UI for a moment, then release it showing the view with all 200 empty charts and after a bit refreshing the view with the populated charts.

I also tried to put the binding inside a thread like this:

private void List_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
    //Find the selected itemsource
    string runName = (string)ExperimentList.SelectedItem;
    ExperimentalRun selectedRun = _experimentRuns.Find(item => item.Name == runName);

    //bind datasource thru a new thread
    Thread newThread = new Thread(lstProductsNewSource);
    newThread.Start(selectedRun);
}

private void lstProductsNewSource(Object selectedRun)
{
    this.Dispatcher.BeginInvoke(DispatcherPriority.Background, (ThreadStart)delegate()
    {
        lstProducts.ItemsSource = ((ExperimentalRun)selectedRun).RunGraphData;
    });
} 

lstProducts is the name of the listview that has the tileview of the charts. The RunGraphData porperty points at a list of a list of datapoints.

I was hoping that this will release the UI but that did not work. In this case there is no time consuming process by itself before the databind, the data is readily available in memory, what is time consuming is the creation of the viewitems and the databinding of them, not the rendering.

As additional details I will like to specify that the charts are generated by a usercontrol and here is how the xml of the tile view looks:

<local:TileView x:Key="ImageView">
    <local:TileView.ItemTemplate>
        <DataTemplate>
            <StackPanel Width="150" VerticalAlignment="Top">
                <local:graph DataSeries="{Binding IsAsync=True, Path=Data}"/>
                <TextBlock TextWrapping="Wrap" HorizontalAlignment="Center"  Text="{Binding >IsAsync=True, Path=ContainerName}" ></TextBlock>
            </StackPanel>
        </DataTemplate>
    </local:TileView.ItemTemplate>
</local:TileView>

The graph usercontrol is a typical chart control that receives the dataset and binds it.

I seek advice on how to manage to keep my UI responsive while the listview is binding. Can you help me?

Edit:

I forgot to mention that I tried to use virtualization on the listview without any noticeable difference:

<ListView Name="lstProducts" View="{StaticResource GridView}" >VirtualizingStackPanel.IsVirtualizing="True" >
</ListView>

I was expecting that it will load the current window worth of items and that when I scroll down it will start loading new items, but even when I use the IsVirtualizing property set to true it seems to load all at once, same delay and even if I scroll down there is no extra delay giving me the impression that all the items are already present.

Edit 2:
I found another question in this site with an answer that provided a type of solution: link

Following the advice provided in the after mentioned thread, I modified my previous threading attempt from trying to encapsulate the entire databinding event into a single background thread to pumping the data one graph at a time, by taking advantage of the ObservableCollection auto-updating properties. Basically I create an empty datasource and assign it, then I add elements to the datasource one by one by creating a thread with background priority every time I add a point. This looks like this:

private void ExperimentList_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
    //Find the selected itemsource
    string runName = (string)ExperimentList.SelectedItem;
    ExperimentalRun selectedRun = _experimentRuns.Find(item => item.Name == runName);

    //create and empty datasource to be filled one item at a time
    ExperimentalRun pumpRun = new ExperimentalRun(((ExperimentalRun)selectedRun).Name);
    lstProducts.ItemsSource = pumpRun.RunGraphData;

    //fill the emtpy source using a new thread per item added
    foreach (var item in selectedRun.RunGraphData)
    {
        PumpExperimentalRunData pump = new PumpExperimentalRunData(pumpRun, item);
        Thread newThread = new Thread(PumpAdd);
        newThread.Start(pump);
    }
}

private void PumpAdd(object PumpExperimentalRunData)
{
    this.Dispatcher.BeginInvoke(DispatcherPriority.Background, (ThreadStart)delegate()
    {
            ((PumpExperimentalRunData)PumpExperimentalRunData).PumpRun.RunGraphData.Add(((PumpExperimentalRunData)PumpExperimentalRunData).Item);
    });
}

This approach seems to work, but I am worried that it creates too many threads (200) every time I change datasource … What I have read so far recommends to use just a few threads, and this doesn’t qualify as a few I think. I will like to do it differently, but I am out of ideas.

Can anyone see the error of my ways or point out a better approach?

  • 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-23T15:22:23+00:00Added an answer on May 23, 2026 at 3:22 pm

    You have to use VirtualizingStackPanel.

    <ListView.ItemsPanel>
      <ItemsPanelTemplate>   
          <VirtualizingStackPanel/>                 
      </ItemsPanelTemplate>  
    </ListView.ItemsPanel>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

New to wpf and through a learning curve. I have a userControl with a
I'm new to WPF. I have a WPF Window with a bunch of Labels
I am new to WPF. I have a ListBox that has its ItemSource set
I'm having some problems with data binding in WPF. Here's the scenario: I have
When I create a new WPF application in Visual Studio 2012 the platform target
While designing a new WPF application I noticed exceptions not being thrown during data
Doing the below will reproduce my problem: New WPF Project Add ListView Name the
New to wpf and therefore struggling a bit. I am putting together a quick
being new to WPF this is a complex problem for me. What i want
I'm pretty new to WPF however i've got a solid understanding of WindowsForms. When

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.