I have the following Loaded event on my Window:
void Window_Loaded(object sender, RoutedEventArgs e) {
this.DataContext = new MyObject() {
MyDateTime = DateTime.Now,
MyNotEmptyString = "Not Empty",
MyNotUpperCaseString = "not upper case",
MyInteger = 20,
MyIntegerInRange = 1,
MyDouble = 4.56
};
}
For each property initialized above, I have a TextBox that binds to it, each having its own validation rule(s) associated with it.
The problem is, my Validation Rules are not being run the very first time when this.DataContext is set, but work great when the form is used normally (they are run when the TextBox loses focus). What could be the reason behind this? I tried setting UpdateSourceTrigger="PropertyChanged", but that didn't help.
Edit:
Here is an example of a TextBox that is binding to a property:
<TextBox Name="MyDoubleField">
<TextBox.Text>
<Binding Path="MyDouble">
<Binding.ValidationRules>
<local:TextIsDouble/>
</Binding.ValidationRules>
</Binding>
</TextBox.Text>
</TextBox>