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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:30:29+00:00 2026-05-25T23:30:29+00:00

I have a textbox that is bound to a property that requires a value,

  • 0

I have a textbox that is bound to a property that requires a value, ie:

 [Required(ErrorMessage = "required value")]
 public string SomeText
 {
     //get set...
 }

And in my XAML, I have the following setup for my textbox:

 UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=true, ValidatesOnExceptions=true

As expected, the red border appears when there is no value in the textbox, however when I select a different tab and then go back to the page with the invalid results, the red border no longer appears. It only reappears if I enter a valid result and then erase it.

How can I debug this? How can I find out what event causes the red border to appear?

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

    In WPF when items on the tab get unloaded from the visual tree the fact that they were marked invalid is lost. Basically, when a validation error happens the UI responds to an event in the validation stack and marks the item invalid. This marking doesn’t get re-evaluated when the item comes back into the visual tree unless the binding is also re-evaluated (which it usually isn’t if the user clicks on a tab item).

    Define a function like this somewhere (I put it in a static ValidationHelper class along with some other things):

    public static void ReMarkInvalid( DependencyObject obj )
    {
        if( Validation.GetHasError( obj ) ) {
            List<ValidationError> errors = new List<ValidationError>( Validation.GetErrors( obj ) );
            foreach( ValidationError error in errors ) {
                Validation.ClearInvalid((BindingExpressionBase)error.BindingInError);
                Validation.MarkInvalid((BindingExpressionBase)error.BindingInError, error);
            }
        }
    
        for( int i = 0; i < VisualTreeHelper.GetChildrenCount( obj ); i++ ) {
            ReMarkInvalid( VisualTreeHelper.GetChild( obj, i ) );
        }
    }
    

    I think you can call this function in the TabControl’s Selected event and it should have the desired effect. E.g.:

    private void TabControl_Selected(...) 
    {
        ReMarkInvalid( tabControl );
    }
    

    If that doesn’t work you may need to do this at a lower Dispatcher priority to make sure the visual tree has finished loading first. Which would look like replacing ReMarkInvalid… with:

    Dispatcher.BeginInvoke( new Action( delegate()
    {
        ReMarkInvalid( tabControl );
    } ), DispatcherPriority.Render );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a TextBox that is bound to a Text-property on an Entity-object. I'd
I have a textbox that i am binding to the viewmodel's string property. The
I have a UserControl that contains a TextBox. The TextBox.Text property is data-bound and
I have a TextBox that is bound to my ViewModel. The TextWrapping property of
I have a textbox that is bound to a property on my ViewModel called
I have a TextBox control on my form that is bound to a property
I have a TextBox that has the TextChanged event set declaratively. In some cases,
I have a multiline textbox that by default, is set to ReadOnly. I would
I have a class that is bound to GUI elements as follows: <TextBox Style={StaticResource
I have a NumericUpDown control that is bound to an int property on a

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.