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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T01:20:54+00:00 2026-05-16T01:20:54+00:00

I realize this question could be boiled down to Why is my code so

  • 0

I realize this question could be boiled down to “Why is my code so slow?” but I’m hoping to get more out of that. Let me explain my code.

I have a class that implements INotifyPropertyChanged in order to do binding, and that class looks similar to this:

  public class Employee : INotifyPropertyChanged 
    { 
        string m_strName = "";
        string m_strPicturePath = "";
        public event PropertyChangedEventHandler PropertyChanged;

        public string Picture
        {
            get { return this.m_strPicturePath; }
            set { this.m_strPicturePath = value; 
            NotifyPropertyChanged("Picture"); }
        }

        public string Name
        {
            get { return this.m_strName; }
            set { this.m_strName = value;
            NotifyPropertyChanged("Name");
            }
        }

        private void NotifyPropertyChanged(String pPropName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(pPropName));
            }
        }
    }

In my XAML I’ve created a DataTemplate that binds to this object:

 <DataTemplate x:Key="EmployeeTemplate">
        <Border Height="45" CornerRadius="0" BorderBrush="Gray" BorderThickness="0" Background="Transparent" x:Name="bordItem">
            <Grid Width="Auto">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*"/>
    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <TextBlock Text="{Binding Path=Name}" VerticalAlignment="Center" Padding="10" HorizontalAlignment="Stretch" FontWeight="Bold" FontSize="20"/>
                <Image Grid.Column="1" Source="{Binding Path=Picture}"></Image>
            </Grid>
        </Border>
    </DataTemplate>

and then put this template on a ListBox:

<ListBox x:Name="lstEmployees" ItemTemplate="{DynamicResource EmployeeTemplate}" VirtualizingStackPanel.VirtualizationMode="Recycling" VirtualizingStackPanel.IsVirtualizing="True"></ListBox>

So in code it’s set as:

lstEmployees.ItemsSource = this.m_Employees;

the “m_Employees” list gets hydrated at app startup from a database, and then after that happens I set the above line of code. The ListBox is on a TabControl.

Now, my actual problem: My “m_Employees” list is returning about 500+ employees from the database, so the collection is slightly big. I get a performance hit in WPF only when the application first starts up and someone navigates to that tab with the ListBox on it. The UI freezes for about 3 seconds, but only when the app first starts up – afterwards it’s fine.

Could this be because:

  • The code has to hit the hard drive to go find the image of each employee?
  • I am doing Virtualizing incorrectly?
  • EDIT
  • WPF is doing the rendering using my DataTemplate once, only when someone navigates to that TabControl, and is suddenly trying to draw 500+ employee items? If so, is there any way to “preload” the ListView in WPF?

Any other suggestions for improving the above would be apprecated. Thanks for reading and for any advice ahead of time.

-R.

  • 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-16T01:20:55+00:00Added an answer on May 16, 2026 at 1:20 am
    1. Wrap m_Employees with a public
      property (Employees)
    2. Instead of setting your ItemsSource in the code like you do, set it with Binding and set IsAsync to
      True.

    ItemsSource=”{Binding Empolyess, IsAsync=True}”

    You can also assign the Binding in the code.

    Hope this helps.

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

Sidebar

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.