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

  • Home
  • SEARCH
  • 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 984909
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T05:05:12+00:00 2026-05-16T05:05:12+00:00

I have a class that is bound to GUI elements as follows: <TextBox Style={StaticResource

  • 0

I have a class that is bound to GUI elements as follows:

<TextBox Style="{StaticResource ValidatedTextBox}" 
  Text="{Binding MaxDistance, ValidatesOnExceptions=True}" >
  <TextBox.Style>
    <Style TargetType="TextBox" >
      <Style.Triggers>
        <Trigger Property="Validation.HasError" Value="True">
          <Setter Property="ToolTip">
            <Setter.Value>
              <Binding Path="(Validation.Errors).CurrentItem.ErrorContent"
                RelativeSource="{RelativeSource Self}" />
            </Setter.Value>
          </Setter>
        </Trigger>
      </Style.Triggers>
    </Style>
  </TextBox.Style>
</TextBox>

The setter for the MaxDistance property is implemented here:

public float MaxDistance
{
  get { return m_maxDistance; }
  set
  {
    // Check for valid values
    if (value < MinDistance)
      throw new ArgumentException(
        "Max distance must be greater than min distance");

    m_maxDistance = value;
  }
}

The trouble is, when I enter an invalid value into the TextBox, the tooltip that appears says “Exception has been thrown by the target of an invocation” instead of “Max distance must be greater than min distance”.

What should I be doing to get the tooltip to read the ArgumentException’s string?
NOTE: Standard type conversion exceptions must still display properly too (i.e. If I enter a string instead of a float the standard error message should still appear).

I can’t move the exceptions into an IDataErrorInfo interface, as the data mustn’t be set on the object if it is invalid, and due to the property’s interdependance on other properties of the object this validation can’t be done via converters or typical validation rules…

In the above example, the validation is there and working, it just isn’t presenting useful information to the user.

Thanks for the help

  • 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-16T05:05:13+00:00Added an answer on May 16, 2026 at 5:05 am

    It appears the only way to get around this problem is to make the tooltip binding smarter.

    I changed the binding on the tooltip to be this:

    <Binding Path="(Validation.Errors)[0]"
         RelativeSource="{RelativeSource Self}"
         Converter="{StaticResource ValidationExceptionConverter}"/>
    

    And implemented the converter as follows:

        public class ValidationExceptionConverter : IValueConverter
        {
            #region IValueConverter Members
    
            // From string to 
            public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
            {
                ValidationError error = value as ValidationError;
                if (error == null)
                    return null;
    
                Exception exception = error.Exception;
                if (exception == null)
                {
                    return error.ErrorContent;
                }
                else
                {
                    // Find the innermost exception
                    while (exception.InnerException != null)
                        exception = exception.InnerException;
    
                    // Use it's message as output
                    return exception.Message;
                }
            }
    
            public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
            {
                throw new NotImplementedException();
            }
    
            #endregion
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class that implements the INotifyPropertyChanged interface. If I create a new
I have a User class and an Author class that extends User. I have
I am developing an Windows phone7 application, I have a .NET webservice that returns
In MVVM it is normal to connect View to the ViewModel with data binding.
I'm building a MVC web app that consist of 3 projects. One for the
I am new to WPF so after reading for a while I deduce that
That's the best way I could think of to phrase my question, here is
I am running into a peculiar issue with an app which has multiple Activities.
I'm working on my first C#/WPF project (I'm a Java/Web developer with some Flex/As
I am quite new to WPF and I am confused about how Data Bindings

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.