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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:36:07+00:00 2026-06-14T17:36:07+00:00

I want change the ListView’s item background dynamicly, so I using the Timer as

  • 0

I want change the ListView’s item background dynamicly, so I using the Timer as the event trigger. But after the timer is triggered, the background color can not refresh automatically until I resize the window. Here is my code snippet:

    public MainWindow()
    {
        InitializeComponent();
        ObservableCollection<Object> People = new ObservableCollection<Object>();
        for (int i = 0; i < 10; i++)
            People.Add(new Person());
        listView.ItemsSource = People;

        System.Timers.Timer _timer = new System.Timers.Timer(10);
        _timer.Elapsed += new System.Timers.ElapsedEventHandler(theObjectDroped);
        _timer.AutoReset = true;
        _timer.Enabled = true;
    }

    public void theObjectDroped(object source, System.Timers.ElapsedEventArgs e)
    {
        for (int i = 0; i < listView.Items.Count; i++)
        {
            Dispatcher.Invoke(new Action<int, Brush>(ModifyListViewBackground), i, Brushes.Red);
        }
    }

    private void ModifyListViewBackground(int i, Brush brush)
    {
        listView.ItemContainerGenerator.StatusChanged += (s, e) =>
        {
            ListViewItem row = listView.ItemContainerGenerator.ContainerFromIndex(i) as ListViewItem;
            if (row != null && row.Background != brush)
            {
                row.Background = brush;
            }
        };
    }
  • 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-06-14T17:36:08+00:00Added an answer on June 14, 2026 at 5:36 pm

    In this line you are setting up a event handler for the StatusChanged event:

        listView.ItemContainerGenerator.StatusChanged += (s, e) =>
    

    This gets fired when you do something like change the size of the window, which is why you only see the background colour change when you do something like resize the window.

    To make it work as soon as the timer event gets fired, just remove the event handler in your ModifyListViewBackground method:

        private void ModifyListViewBackground(int i, Brush brush)
        {
            ListViewItem row = listView.ItemContainerGenerator.ContainerFromIndex(i) as ListViewItem;
            if (row != null && row.Background != brush)
            {
                row.Background = brush;
            }
        }
    

    N.B. your timer is set up to trigger after 10ms. This is very fast, when trying this it was almost instantaneous. I set it to 1s (1000ms) so as I could see the event triggering after the timeout.

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

Sidebar

Related Questions

I want to change background color of selected item in listview. When I click
I want to change the background of a listview item when the user clicks
I want to Change the background image of ListView automatically after a time interval
I want to change Textview Color and Imageview image on listview click event &
I want to change color of ListView separator line.
I want to change data on listview runtime after button click... here is my
I have a RadioButtnList. I want change body background color based on radio button
So I have a ListView and I want to change the color of each
I have a textbox in a listview itemtemplate. I want to change the background
I want to change the background colour of the rectangle in the IsMouseOver trigger,

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.