I'm rather new to WPF and XAML, and I'm attempting to create a custom class that extends TextBox, so that I can add some properties for easier validation setup. The validation works fine. The problem is, when I swap out the TextBox in the XAML, the new TextBox updates the border to display an error, but the tool-tip does not show up as expected (see below).
In the picture below, the top 's error tool tip displays correctly, but the 's tool-tip doesn't.
Here's the XAML...
<TextBox x:Name="StrTextBox3" Width="200" Height="50">
<TextBox.Text>
<Binding Path="BinaryIntText" UpdateSourceTrigger="PropertyChanged">
<Binding.ValidationRules>
<validationRules:StrValidationRule ValidatorType="{x:Static validators:StringValidator.BinaryOnly_Validator}"/>
</Binding.ValidationRules>
</Binding>
</TextBox.Text>
</TextBox>
<validationRules:ValidatedTextBox x:Name="VText" Width="200" Height="50">
<TextBox.Text>
<Binding Path="BinaryIntText2" UpdateSourceTrigger="PropertyChanged">
<Binding.ValidationRules>
<validationRules:StrValidationRule ValidatorType="{x:Static validators:StringValidator.BinaryOnly_Validator}"/>
</Binding.ValidationRules>
</Binding>
</TextBox.Text>
</validationRules:ValidatedTextBox>
And here's the extending class...
class ValidatedTextBox : TextBox
{
public ValidatedTextBox()
{
//
}
}
And the ValidationRule for good measure...
public override ValidationResult Validate(object value, CultureInfo cultureInfo)
{
return ValidatorType.Validate(Convert.ToString(value)).Match (
Right: result => new ValidationResult(true, null),
Left: error => new ValidationResult(false, error));
}
How do I go about enabling this functionality? Have I not initialized a particular field or two? Am I missing calls to something else? Am I plagued by styles, or some other straight-forward thing that is a quicker fix than doing this write up?
Thank you
Turns out I'm dense; by simply extending the TextBox, the default Style for TextBoxes was not applied, and setting the new Style to an existing TextBox's Style, or just setting in at all, fixed the issue.