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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:45:09+00:00 2026-06-18T10:45:09+00:00

I have a TextBox on WPF that I want to validate. I’m using Binding

  • 0

I have a TextBox on WPF that I want to validate. I’m using Binding to validate it:

<TextBox Text="{Binding Path=Name, UpdateSourceTrigger=Explicit}" TabIndex="0" LostFocus="TextBox_OnLostFocus">
</TextBox>

The LostFocus event:

private void TextBox_OnLostFocus(object sender, RoutedEventArgs e)
{
    ((Control) sender).GetBindingExpression(TextBox.TextProperty);
}

Code behind the validation:

public string Name
{
    get { return _name; }
    set
    {
        _name = value;
        this.OnPropertyChanged(new PropertyChangedEventArgs("Name"));

    }
}

public string Error { get { return this[null]; } }

public string this[string columnName]
{
    get
    {
        string result = string.Empty;
        columnName = columnName ?? string.Empty;
        if (columnName == string.Empty || columnName == "Name")
        {
            if (string.IsNullOrEmpty(this.Name))
            {
                result += Properties.Resources.ValidationName + Environment.NewLine;
            }
        }
        return result.TrimEnd();
    }
}

I have some questions:

1. When I first load my Window, my control is surrounded by a red square (the validation one), but I want it to appear only when I fire it (on the Explicit side).

2. How can I know if all my fields have been validated? I mean, when I press a button I only need to know how to know if all controls have been validated.

NOTE: I do have this context on the Constructor:

User u = new User();
DataContext = u;
  • 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-18T10:45:10+00:00Added an answer on June 18, 2026 at 10:45 am
    1. Your first question may be answered here Did you try setting the binding mode to Default?
    2. The Validation.HasError Attached Property will tell you if any binding on a particular UI Element has any binding validation errors. Use that on every control you need to have validated. Try that first. If you are using a pattern like MVVM, you could create properties on your VM to bind to the Validation.HasError properties.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a WPF TextBox, defined like this: <TextBox Text={Binding Path=/Comments} Margin=351,193.91,10,36 x:Name=txtComments IsReadOnly=True
I have the following binding in my wpf application xaml: <TextBox Text={Binding Amount, StringFormat=c}
I have a WPF textBox that is declared as ReadOnly <TextBox IsReadOnly=True IsTabStop=False Width=200
I have a WPF TextBox in which I want to allow autocompleting user names
I want to make a WPF TextBox have a DarkBlue border and thickness equal
I have a WPF listbox control that is declaratively bound to a textbox. The
I have a WPF application, and I am attempting to style a TextBox using
I have a button in WPF, I want to change the text when I
I'm new to WPF....I have tried implementing controltemplate and datatriggers both for textbox..I want
I have a listbox that in which every item is represented using a textbox.

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.