I've followed Microsoft's short tutorial on implementing binding validation in WPF and it's working nicely.
However, I need to expose the result of the validation on the view model, so that my application can prevent the user progressing, but I can't see a way to achieve this.
The XAML for my control is below, with StartDateRule
defined as a class that inherits from ValidationRule
<controls:DateInputBox
Grid.Column="2"
Grid.Row="3"
Height="28"
HorizontalAlignment="Left"
Watermark=""
Width="110"
VerticalAlignment="Center">
<controls:DateInputBox.SelectedDate>
<Binding Path="SelectedDate">
<Binding.ValidationRules>
<local:StartDateRule/>
</Binding.ValidationRules>
</Binding>
</controls:DateInputBox.SelectedDate>
</controls:DateInputBox>
I tried to create an instance of the StartDateRule
class in my view model, and bind to this. The idea being that I can expose some Validate()
method on the view model that would call the Validate()
method on the rule. But I can't seem to create this binding. I'm not sure if this is because I don't have the syntax right, or because it's just not possible.
I've read a lot of stuff on using the INotifyDataErrorInfo
interface, but this seems to have a lot of boilerplate code, and I can't find good official documentation on this.
Is what I'm trying to achieve possible?