I'm trying to understand how a TextBox
element/class in WPF can have the validation
property e.g. in the code below that is in every tutorial I follow
<Style TargetType="TextBox">
<Setter Property="FontSize" Value="20">
</Setter>
<Style.Triggers>
<Trigger Property="Validation.HasError" Value="True">
<Setter Property="Background" Value="Red"/>
</Trigger>
</Style.Triggers>
</Style>
From what I understand, Trigger
will track the value of Validation.HasError
property of TextBox
. However, I looked into the source code of TextBox
and its parent classes, and nowhere there is a Validation
property defined. So how does it exist in TextBox
? I saw that TextBox
and Validation
classes are inside the same namespace System.Windows.Controls
. Does that have anything to do with this?
And just to check my understanding, if I implement INotifyDataErrorInfo
in a view model, then the Validation
class of Microsoft (which I can't decompile) would internally track the ErrorsChanged
event and set its HasError
property to equal my implementation of HasErrors
from the INotifyDataErrorInfo
e.g. it would do something like this:
public Validation(...){
...
Errors += ErrorsChanged
...
}
private void Errors()
{
...
HasError = myImplementationOfINotifyDataErrorInfo.HasErrors
}
or maybe
public Validation(...){
...
}
public static readonly DependencyProperty HasErrorProperty =
DependencyProperty.Register(
name: "HasError",
propertyType: typeof(bool),
ownerType: typeof(Validation),
typeMetadata: new FrameworkPropertyMetadata(null, ErrorsChanged));
}
Am I right? For some reason I seem to can't open Validation
class; I tried go to implementation
in Visual Studio but it says it can't find the file.