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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:17:02+00:00 2026-05-20T05:17:02+00:00

I am trying to add validation to a datagrid in XAML. Currently, I have

  • 0

I am trying to add validation to a datagrid in XAML.

Currently, I have created a method which checks 3 textboxes for valid input and if false sets a value in the collection the datagrid is bound to, to either true or false. This part works fine.

The problem I am now having is making this actually work.

I have created a converter :

 public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  {
     bool isRowValid = ((bool)value);

     ConsoleColor validColour = ConsoleColor.Green;
     ConsoleColor invalidColour = ConsoleColor.Red;

     if (isRowValid)
     {
        return validColour;
     }
     else
     {
        return invalidColour;
     }
  }

So when the row is invalid it will display red, when valid it will display green.

The method to validate each row gets called when the row looses focus, and by default each row is set to invalid.

I have been attempting to set the background for each row by doing

<DataGrid.RowBackground>
    <SolidColorBrush Color="{Binding Path=IsRowValid, Converter={StaticResource RowValidConverter}}" />
</DataGrid.RowBackground>

but ideally, I would like this to only adjust the text colour and not the background.

Any suggestions on how to implement this would be greatly appreciated,

Thanks.

  • 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-20T05:17:03+00:00Added an answer on May 20, 2026 at 5:17 am

    If I understand your problem correctly then I think an easier approach is to add a Trigger for Validation.HasError in the RowStyle

    <DataGrid ...>
        <DataGrid.RowStyle>
            <Style TargetType="DataGridRow">
                <Setter Property="TextElement.Foreground" Value="Green"/>
                <Style.Triggers>
                    <Trigger Property="Validation.HasError" Value="True">
                        <Setter Property="TextElement.Foreground" Value="Red"/>
                    </Trigger>
                </Style.Triggers>
            </Style>
        </DataGrid.RowStyle>
        <!--...-->
    </DataGrid>
    

    Or if you’re controling this some other way with a Property called IsRowValid in your ViewModel then you can just change the Trigger to a DataTrigger

    <DataTrigger Binding="{Binding IsRowValid}" Value="True">
        <Setter Property="TextElement.Foreground" Value="Red"/>
    </DataTrigger>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very basic entity model which I'm trying to add custom validation
I have decided to add some validation to my combobox, what I'm trying to
I'm trying to add a validation rule to multiple textboxes dynamically. Here's the js:
I'm trying to dynamically add a validation rule to some dynamic controls: $(input[id*=Hours]).rules(add, required);
I'm trying to add entity to SQL CE 4 which have property of type
I'm trying to add validation to a dynamic input field. What I'm doing is
I'm trying to add some Input Validation in Classic ASP by using the function/code
I am trying to add validation logic into my application. I have tried to
I'm trying to add extra validation to jdpl process-definition files using XSD. We have
I'm trying to add custom validation to a dynamically created control. Can I use

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.