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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:39:45+00:00 2026-06-15T16:39:45+00:00

I would like to make WPF Window that contains DataGrid control and enables following

  • 0

I would like to make WPF Window that contains DataGrid control and enables following scenario in C# WPF DataGrid: Data is loaded in DataGrid, application validates data in background (parallel async operations), when row is determined to be valid its bacground color becomes green, red otherwise. What is cleanest way to program this behaviour? Is there any built-in functionality in DataGrid and WPF to do this kind of validation?

EDIT:
For now I have manged to perform this by using RowStyle, but this makes application non responsive because validation takes time for each row, so I would like to make this async and parallel.

<DataGrid.RowStyle>
    <Style TargetType="{x:Type DataGridRow}">
        <Setter Property="Background" Value="{Binding BgColor}">
        </Setter>
    </Style>
</DataGrid.RowStyle>

EDIT2:
Here is progress:

<DataGrid.RowStyle>
    <Style TargetType="{x:Type DataGridRow}">
        <Style.Triggers>
            <DataTrigger Binding="{Binding Path=BgColor}" Value="DarkRed">
                <Setter Property="Background" Value="DarkRed"/>
            </DataTrigger>
        </Style.Triggers>
    </Style>
</DataGrid.RowStyle>

Code behind looks like this:

Func<List<bool>> func = () => data.AsParallel().Select(x => File.Exists(x.FullPath)).ToList();
List<bool> res = null;
IAsyncResult ar = func.BeginInvoke(new AsyncCallback(x=>
{
    res = ((Func<List<bool>>)((AsyncResult)x).AsyncDelegate).EndInvoke(x);
    for (int i = 0; i < res.Count; ++i)
        if (!res[i])
            data[i].BgColor = Brushes.DarkRed;
}), null);

Remaining problem is that row background color is refreshed only when row is redrawn (moved out of view and than into view again). Any clean and easy way to fix this?

EDIT3:
Finally everything works exactly as required, only thing missing in EDIT2 was to implement INotifyPropertyChanged in data source class.

  • 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-15T16:39:46+00:00Added an answer on June 15, 2026 at 4:39 pm

    Well the best approach would be using a DataTrigger in the style of the DataGridItems and provide a property (bool?) in the ViewModel which is bound to the DataTrigger. In the DataTrigger you could declare the visual for all three states Null, True, False

    For additional information on DataTrigger, please have a look here.

    Edit

    Hmm, any chance to put the highlighting functionality in a DataTemplate? I implemented a highlighting for the selection state of an entity. And it works as expected.

    <DataTemplate.Triggers>
      <DataTrigger Binding="{Binding IsSelected, RelativeSource={RelativeSource AncestorType=ListBoxItem}}"
                      Value="true">
      <!-- Expand -->
      <DataTrigger.EnterActions>
        <BeginStoryboard>
          <Storyboard Storyboard.TargetName="CommandPanel">
            <DoubleAnimation Duration="0:0:0.200" Storyboard.TargetProperty="Opacity" To="1" />
            <DoubleAnimation Duration="0:0:0.150" Storyboard.TargetProperty="Height"
                                To="{StaticResource TargetHeightCommandPanel}" />
          </Storyboard>
        </BeginStoryboard>
      </DataTrigger.EnterActions>
      <!-- Collapse -->
      <DataTrigger.ExitActions>
          <BeginStoryboard>
            <Storyboard Storyboard.TargetName="CommandPanel">
              <DoubleAnimation Duration="0:0:0.100" Storyboard.TargetProperty="Opacity" To="0" />
              <DoubleAnimation Duration="0:0:0.150" Storyboard.TargetProperty="Height" To="0" />
            </Storyboard>
          </BeginStoryboard>
        </DataTrigger.ExitActions>
      </DataTrigger>
    </DataTemplate.Triggers>
    

    Btw, have you ever heard of MVVM?

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

Sidebar

Related Questions

I would like to find an example of a WPF Datagrid that has row
there is some default functionality on a WPF application that i would like to
Would like to make anapplication in Java that will not automatically parse parameters used
I would like to make a function that takes in a list of integers
I would like to remove the resizing border from my WPF custom window. I
I'm would like to embed Internet Explorer into an WPF Windows Application. I have
I would like to make a library of some of my commonly used WPF
I have a touch screen keyboard in my WPF application and I would like
I would like to make a window as a container base window for the
I have a simple class that contains a string and an WPF Image control:

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.