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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T21:23:33+00:00 2026-05-17T21:23:33+00:00

I hope that this question has not been asked elsewhere, but I’m having difficulty

  • 0

I hope that this question has not been asked elsewhere, but I’m having difficulty finding the right search terms to bring up any already-existing answers to this problem.

I’m implementing a program in C# WPF (MVVM) with many interview-style screens where the user inputs scientific data in an orderly manner. We would like to have the Textbox‘s and DataGrid‘s change Foreground and Background colors on an individual basis based on whether the data in that control has been inputted by the user, inputted as a default value by the program, or is a template value from another file the user imported. On top of this, we would like the UI to respond to validation checks from IDataErrorInfo implemented in the ViewModel.

Thus, the data displayed in a TextBox could be blue if it is a templated value, green if a program default, black if user inputed, and red if IDataErrorInfo says it is bad data.

My initial answer for implementing this was to create a custom class:

class AdornerString{

private string _myString;
private bool _isTemplate;
private bool _isDefault;

public string MyString{ 
  get{
      etc.
  }
  set{
      etc.
  }
}
// accessor properties and Constructors omitted for brevity
}

Then I have all my TextBox.Text properties in the View bound like so:

<TextBox Text="{Binding Path=someAdornerString.MyString,UpdateSourceTrigger=PropertyChanged,ValidatesOnDataErrors=True}"/>

and apply a style with DataTriggers that responds to someAdornerString’s properties to create the appropriate colors.

However, IDataErrorInfo on the ViewModel doesn’t validate the TextBox anymore. Why is this so, and is there a better way to solve my problem? I can’t validate inside the AdornerString class.

A possible work-around, though undesirable:

The only other solution I can think of is to have two properties in the ViewModel for each field entered by the user- one for the data itself and the other being the same custom class as above minus the string. However, this means I can’t generalize the style used for the textboxes. Each TextBox would have to have a custom style something like this:

<TextBox.Style>
    <Style TargetType="{x:Type TextBox}"
           BasedOn="{StaticResource OtherStyle}">
        <Style.Triggers>
            <DataTrigger Binding="{Binding Path=**instanceCustomClass**.IsDefault}"
                         Value="True">
                <Setter Property="Foreground"
                        Value="Green" />
            </DataTrigger>
            <Trigger Property="Validation.HasError"
                     Value="true">
                <Setter Property="Foreground"
                        Value="OrangeRed" />
            </Trigger>
        </Style.Triggers>
    </Style>

since each UI field has a specific custom class associated with it.

I would seriously rather not implement this way, as I have possibly 100+ pages of input screens, with each screen having 1-12 TextBox‘s each, ignoring the DataGrids thrown in the mix (with parellel arrays of data and their associated custom classes).

Any ideas? I’ve read about custom validation, though I yet don’t see how this might help in this case.

  • 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-17T21:23:33+00:00Added an answer on May 17, 2026 at 9:23 pm

    Ignore making use of the IDataErrInfo validation all together, as it seems that the you really want to make it 1 of 4 values…and ‘bad’ data just happens to be one of them.

    You need to keep the items on an even playing field since you are treating them the same, just differentiating colors. Use a single property with an object wrapping the value and the state of the model within the ViewModel. Ignore IDataErroInfo and then use a converter to provide the coloring and then add a delegate to the AdornerString that will be set to the validation function written in the ViewModel for it.

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

Sidebar

Related Questions

This has been driving me nuts. I hope it's not been asked before but
I know this question has been asked here before, but I don't think those
I know this question has been asked a million of times here at stackoverflow,
I'm new to this, so sorry if my question has been asked before. I
I apologize if this has been asked before, but I haven't quite found the
I hope this question does not come off as broad as it may seem
This really, really urks me, so I hope that someone can give me a
I have now 1gb ram at work(i hope that will change soon) and jboss
I just installed the FindBugs plugin for Eclipse, with the hope that it will
I'm starting to get into a side project that I hope to pull in

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.