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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:41:06+00:00 2026-05-25T06:41:06+00:00

Don’t know the term for the red validation border, does it have one? I

  • 0

Don’t know the term for the red validation border, does it have one?

I have a viewmodel that does not inherit from IDataErrorInfo. It binds an int property to a “quantity” textbox, so that when alpha characters are entered it gets a red validation border. This is perfect behavior. That red border is styled by the OS, so it fits. It doesn’t require that I inherit from or implement IDataErrorInfo; it’s simple and automatic.

Is there a way to get this same behavior for texbox’s that are bound to strings, becoming red when the string are empty (or start empty). I know I could bind them to an object that inherits from IDataErrorInfo to do this, but I was wondering if a solution as simple as the one above exists.

I thought that the int binding on quantity threw an exception in the setter when you typed alpha characters. Doing the same in the setter of the string worked if you changed the value to empty, but it wasn’t red if it started out empty (since the setter hasn’t been called), and the setter caused visual studio to jump into the debugger first, which the quantity field doesn’t do.

Is this possible, or is the int validation just a lucky exception?

Edit: HB’s solution below works perfectly, unless you are working on an interface with a tabcontrol. See this SO question for a detailed explanation, but here is the short of it: validation errors are painted on a layer that is discarded when switching tabs. There is a simple solution to this, unless your validation error is raised on a control while it is on a tab that is not currently selected. Suddenly the solution becomes very complicated, and in my opinon, very hacky.

Edit: I have decided a datatrigger is probably the easiest way to handle this, and it is also easy to reuse.

<Style x:Key="TextBoxEmptyError" TargetType="{x:Type TextBox}">
    <Style.Triggers>
        <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=Text.Length}" Value="0">
            <Setter Property="BorderBrush" Value="{StaticResource ResourceKey=SemiTransparentRedBrushKey}"/>
            <Setter Property="BorderThickness" Value="2" />
        </DataTrigger>
    </Style.Triggers>
</Style>
  • 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-25T06:41:07+00:00Added an answer on May 25, 2026 at 6:41 am

    You can add a ValidationRule to the Text-binding which gives an error on empty string input, to make it validate right away set ValidatesOnTargetUpdated to true.

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

Sidebar

Related Questions

Don't know why people do not practice AJAX implementation for authentication systems. Is it
Don't want to sort the entries. using this does not preserve the order as
Don't overthink this - there's a very commonly used term and I ... have
Don't know a whole lot about streams. Why does the first version work using
Don't know if there is a better way to do this, so that is
Don't worry, I'm not going to ask that question, yet again... I am wanting
DON'T ASK WHY but... I have a regex that needs to be case insensitive
Don't know if this has been answered before. Have custom routes to users. If
I don't have much PHP experience and I want to know how to best
Don't ask why but I have the requirement to draw a border around certain

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.