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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:08:37+00:00 2026-05-26T23:08:37+00:00

I am working on a WPF datagrid custom control, where i have a Day

  • 0

I am working on a WPF datagrid custom control, where i have a Day column for each day a week and 24 columns for each hour a day, i save these values in database in seven different columns(each day a week) and datatype for those columns is Binary(3) (3 bytes * 8 bits=24), 1 bit for each hour, my intention is to bind the grid some way so each cell of grid change its color to red/green based on bit value for that hour(red for 0 and green for 1), but i don’t know where to start.

Looping is not preffered, but if there is no way out, then i should go with that as well.

Kindly help.

  • 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-26T23:08:38+00:00Added an answer on May 26, 2026 at 11:08 pm

    Please try this and let me know if this works for you:

    DailyValues can be your array of integers (each integer containing the bit values for each day).

    <UserControl.Resource>
       <HourToBrushConverter x:Key="hourToBrushConverter" />
    </UserControl.Resource>
    
    
    <DataGrid ItemsSource="{Binding DailyValues}" AutoGenerateColumns="False" >
        <DataGrid.Columns>
            <DataGridTemplateColumn Header="1AM" Width="SizeToCells" IsReadOnly="True">
                <DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <Rectangle Fill="{Binding . 
                                   Converter={StaticResource hourToBrushConverter}, 
                                   ConverterParameter=1}" />
                    </DataTemplate>
                </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
    <DataGridTemplateColumn Header="2AM" Width="SizeToCells" IsReadOnly="True">
                <DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <Rectangle Fill="{Binding . 
                                   Converter={StaticResource hourToBrushConverter}, 
                                   ConverterParameter=2}" />
                    </DataTemplate>
                </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
                <!-- add a column for each hour (up to 24) -->
        </DataGrid.Columns>
    </DataGrid>
    
    
    
    [ValueConversion(typeof(int), typeof(Brush))]
    public class HourToBrushConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            int dayValue = (int)value;
            int hourNumber = (int)parameter;
            int mask = GetMask(hourNumber);
    
            return (dayValue & mask) > 0 ? Brushes.Green : Brushes.Red;
        }
    
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotSupportedException();
        }
    
        private static int GetMask(int index)
        {
           return 1 << index;
        }
    }
    

    I don’t have access to a Visual Studio right now so I apologize for any syntax mistake.

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

Sidebar

Related Questions

I am working with WPF DataGrid. I have to drag the Column Header, drop
Hi I'm working with a wpf DataGrid and I'd like to add a column
I have a working WPF dialog that uses DataGrid. The DataGrid is set to
I am working with the the WPF Toolkit DataGrid and currently have a problem
I am working with a Wpf application. I have created a custom style for
I have the following XAML Code: <sdk:DataGrid Margin=58,8,52,18 Name=dataGridTickets> <sdk:DataGrid.Columns> <sdk:DataGridTextColumn x:Name=ticketNoColumn Header=Ticket No.
I've been working with the DataGrid in WPF with great results. However, it is
Im working on a middle size project, using WPF. Need DataGrid, suitable for the
I m working with WPF DataGrid and I want to retrieve a DataGridCell 's
I have a WPF Datagrid populated with data from one SQL table using Entity

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.