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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T21:46:54+00:00 2026-05-13T21:46:54+00:00

Assume I have a class that looks like this: class Sample { public string

  • 0

Assume I have a class that looks like this:

class Sample
{
    public string Value { get; set; }
    public DateTime Begin { get; set; }
    public DateTime End { get; set; }
}

I want to display a list of Sample instances where each one changes color when the current time passes Begin and then changes color again when the current time passes End.

For example, say I have a DataGrid containing a Sample sort of like this:

dataGrid1.ItemsSource = new List<Sample> {
    { Value="123",
      Begin=DateTime.Parse("10:00"),
      End=DateTime.Parse("11:00") } };

How would I get the row showing “123” to be red at 9:59, turn yellow at 10:00, and turn red at 11:00?

EDIT: One thing I’m particularly concerned about is a timer explosion. If I have 10,000 Samples, will it be a problem to have 10k (or 20k) timers? What if I have 1M Samples? I think it might be a better idea to make the timers per grid row rather than per Sample.

  • 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-13T21:46:55+00:00Added an answer on May 13, 2026 at 9:46 pm

    By doing this:

    MainPage.xaml

    <UserControl xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"  x:Class="ColorGridRow.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:ColorGridRow" mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">
    <Grid x:Name="LayoutRoot">
        <data:DataGrid ItemsSource="{Binding}" AutoGenerateColumns="False">
            <data:DataGrid.Columns>
                <data:DataGridTemplateColumn>
                    <data:DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <Grid Background="{Binding RowBackground}">
                                <TextBlock Text="{Binding Value}"/>
                            </Grid>
                        </DataTemplate>
                    </data:DataGridTemplateColumn.CellTemplate>
                </data:DataGridTemplateColumn>
                <data:DataGridTemplateColumn>
                    <data:DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <Grid Background="{Binding RowBackground}">
                                <TextBlock Text="{Binding Begin}"/>
                            </Grid>
                        </DataTemplate>
                    </data:DataGridTemplateColumn.CellTemplate>
                </data:DataGridTemplateColumn>
                <data:DataGridTemplateColumn>
                    <data:DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <Grid Background="{Binding RowBackground}">
                                <TextBlock Text="{Binding End}"/>
                            </Grid>
                        </DataTemplate>
                    </data:DataGridTemplateColumn.CellTemplate>
                </data:DataGridTemplateColumn>
            </data:DataGrid.Columns>
        </data:DataGrid>
    </Grid>
    

    MainPage.xaml.cs

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Linq;
    using System.Windows.Controls;
    using System.Windows.Media;
    
    namespace ColorGridRow
    {
        public partial class MainPage : UserControl
        {
            public MainPage()
            {
                InitializeComponent();
                DataContext = new List<Sample>
                    {
                        new Sample("1", DateTime.Now + TimeSpan.FromSeconds(1), DateTime.Now + TimeSpan.FromSeconds(3)),
                        new Sample("2", DateTime.Now + TimeSpan.FromSeconds(2), DateTime.Now + TimeSpan.FromSeconds(4)),
                        new Sample("3", DateTime.Now + TimeSpan.FromSeconds(3), DateTime.Now + TimeSpan.FromSeconds(5)),
                    };
            }
        }
    
        public class Sample : INotifyPropertyChanged
        {
            private SolidColorBrush _savedRowBackground;
            private SolidColorBrush _rowBackground;
    
            public string Value { get; private set; }
            public DateTime Begin { get; private set; }
            public DateTime End { get; private set; }
    
            public SolidColorBrush RowBackground
            {
                get { return _rowBackground; }    
                set
                {
                    _rowBackground = value;
                    NotifyPropertyChanged("RowBackground");
                }
            }
    
            public event PropertyChangedEventHandler PropertyChanged = delegate { };
    
            private void NotifyPropertyChanged(string propertyName)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
    
            public Sample(string value, DateTime begin, DateTime end)
            {
                Value = value;
                Begin = begin;
                End = end;
                RowBackground = new SolidColorBrush(Colors.Red);
    
                Observable.Timer(new DateTimeOffset(begin)).Subscribe(_ =>
                {
                    _savedRowBackground = _rowBackground;
                    RowBackground = new SolidColorBrush(Colors.Yellow);
                });
    
                Observable.Timer(new DateTimeOffset(end)).Subscribe(_ => RowBackground = _savedRowBackground);
    
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 353k
  • Answers 353k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer If I understand you correctly, what you could do is… May 14, 2026 at 7:38 am
  • Editorial Team
    Editorial Team added an answer Anything you store locally can be compromised. But there are… May 14, 2026 at 7:38 am
  • Editorial Team
    Editorial Team added an answer function makeFriendly($string) { $string = strtolower(trim($string)); $string = str_replace("'", '',… May 14, 2026 at 7:38 am

Related Questions

I have a directory structure that looks like this: project/ __init__.py foo/ __init.py__ first.py
I have a C++/CLI class library project in VS2005 that i am having some
I have been asked to modify an Excel sheet with some arcaic programming. I
So I have a class that looks something like the following: public class MyClass
I have added an EventHandler for the Click-event to a picturebox but on runtime

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.