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

  • Home
  • SEARCH
  • 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 7167759
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:38:32+00:00 2026-05-28T14:38:32+00:00

I have quastion about DataGrid in WPF .NET 4. Here is XAML code with

  • 0

I have quastion about DataGrid in WPF .NET 4.

Here is XAML code with DataGrid:

    <DataGrid Name="m_DataGrid">
        <DataGrid.Columns>
            <DataGridTextColumn Binding="{Binding Path=Name}">
                <DataGridTextColumn.CellStyle>
                    <Style TargetType="{x:Type DataGridCell}">
                        <Style.Triggers>
                            <Trigger Property="IsSelected" Value="True" >
                                <Setter Property="Background" Value="Gray" />
                                <Setter Property="Foreground" Value="White" />
                                <Setter Property="BorderBrush" Value="Gray" />
                            </Trigger>
                            <DataTrigger Binding="{Binding Path=IsRed}" Value="True">
                                <Setter Property="Foreground" Value="Red" />
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </DataGridTextColumn.CellStyle>
            </DataGridTextColumn>
        </DataGrid.Columns>
    </DataGrid>

And there are methods in window code:

    private void Window_Loaded(object sender, RoutedEventArgs e)
    {
        for (int i = 0; i < 100; i++)
        {
            m_DataGrid.Items.Add(new MyItem(string.Format("Item {0}", i)));
        }
    }

    private void Window_PreviewKeyDown(object sender, KeyEventArgs e)
    {
        if (e.Key == Key.Space)
        {
            e.Handled = true;
            ((MyItem)m_DataGrid.SelectedItem).IsRed = !((MyItem)m_DataGrid.SelectedItem).IsRed;
            m_DataGrid.SelectedIndex++;
            m_DataGrid.Items.Refresh();
        }
    }

And here is MyItem class Code:

public class MyItem
{
    public string Name { get; set; }
    public bool IsRed { get; set; }

    public MyItem(string _Name)
    {
        Name = _Name;
        IsRed = false;
    }
}

The problem is, that I must use method m_DataGrid.Items.Refresh(); to show items in red color. But when I have eg. 100 items this method is too slow. So when I hold down spacebar items are marked with red color very slowly. How to do this in better and more elegant way? How to change item color without Refresh method?
Thank you for your answers and tips.

  • 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-28T14:38:33+00:00Added an answer on May 28, 2026 at 2:38 pm

    Your class, MyItem should inherit from INotifyPropertyChanged, and the IsRed property declared as…

    private bool _isRed;
    public bool IsRed
    {
        [DebuggerStepThrough]
        get { return _isRed; }
        [DebuggerStepThrough]
        set
        {
            if (value != _isRed)
            {
                _isRed = value;
                OnPropertyChanged("IsRed");
            }
        }
    }
    

    With this scheme, when your code changes IsRed to true, the subscribers will be notified and your grid will make the appropriate update. This will achieve the result you are looking for.

    The ‘Refresh’ method of the DataGrid is inappropriate for changes to a property.

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

Sidebar

Related Questions

Have a question about the design/usage of asp.net mvc here. In the html helper
I have a performance problem with the (WPF Toolkit) DataGrid. It contains about 1.000
If I have the following DataGrid, how would I go about binding the Visibility
I have a question about using streams in .NET to load files from disk.
I have a question about how to deploy WPF application into a PC without
I have question about throw. How will the throw work in the following code?
still trying to get my DataGrid go faster, I have a question about this:
I am slowly moving into Silverlight from asp.net and have a question about how
I have question about Dictionaries in Python. here it is: I have a dict
I have a datagrid that I'm building the contents of programmatically as the columns

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.