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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T22:35:26+00:00 2026-05-15T22:35:26+00:00

I (believe) I’m wiring up DataBinding Validation in a textbook manner, but it just

  • 0

I (believe) I’m wiring up DataBinding Validation in a textbook manner, but it just isn’t working – at all.

In the debugger, the Validate(object value, CultureInfo cultureInfo) method is never called.

What gives? Also, for bonus points, any pointers on debugging WPF would be awesome.

I’m posting my XAML and the class in question

<UserControl x:Class="FooControl"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
         xmlns:local="clr-namespace:Foo.Controls"
         mc:Ignorable="d" 
         d:DesignWidth="300">
<Grid Name="GridFoo">
    <Grid.Resources>
        <local:ValueConverter x:Key="MyConverter" />
    </Grid.Resources>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*" />
        <ColumnDefinition Width="Auto" />
    </Grid.ColumnDefinitions>
    <TextBox Name="TextBoxScalar" Grid.Column="0" TextAlignment="Right">
        <TextBox.Text>
            <Binding Mode="OneWay" Path="Scalar" NotifyOnValidationError="True" ValidatesOnDataErrors="True" ValidatesOnExceptions="True">
                <Binding.ValidationRules>
                    <local:ScalarValidationRule />
                </Binding.ValidationRules>
            </Binding>
        </TextBox.Text>
    </TextBox>
    <TextBlock Name="TextBlockUnit" Grid.Column="1" TextAlignment="Left" Padding="3">
        <Hyperlink>
            <!-- Use a custom converter here b/c generics break wpf... -->
            <Run Text="{Binding Mode=OneWay, Path=Unit, Converter={StaticResource MyConverter}}" />
        </Hyperlink>
    </TextBlock>
</Grid>

ValidationRule

public class ScalarValidationRule : ValidationRule
{
    public override ValidationResult Validate(object value, CultureInfo cultureInfo)
    {
        string number = value as string;
        double d;
        return new ValidationResult(Double.TryParse(number, NumberStyles.Any, cultureInfo, out d),
            String.Format("\"{0}\" is not a number.", number));
    }
}
  • 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-15T22:35:26+00:00Added an answer on May 15, 2026 at 10:35 pm

    You are adding the ValidationRule to a one-way binding. One-way bindings never push a value to the source, so there is nothing to validate and your ValidationRule is never called. If you want to validate data entered by the user, set Mode="TwoWay" on your binding. You can also omit the Mode attribute completely, since TextBox.Text binds two-way by default.

    If you really do want a one-way binding and you want validation to occur when the value is pushed from the source (Scalar) to the target (TextBox.Text), then set ValidatesOnTargetUpdated to True on the ValidationRule. You can either do this in XAML or in the constructor of your ValidationRule class.

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

Sidebar

Related Questions

I believe it has something to do with draw order, but I've just given
I believe it was working sometime ago but now xpath is returning null. Can
I believe Wordpress stores multiple entries of posts as revisions but I think thats
I believe this is a fairly simple question but it is something I am
I believe I understand how submodule work, but in my case I don't want
I believe this is possible but unsure how to go around it, I need
I believe this has been asked before but no concrete answer has been determined.
I believe lot of people already asked this question before, but i kept getting
I believe it is a simple mistake but I have spent a lot of
I believe task I am trying to accomplish is fairly easy, but I have

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.