How to create a WPF validation rule to ensure two text fields have the same value?
.net, c#, validation, wpf, xaml
Solution
Looks like implementing the `System.ComponentModel.IDataErrorInfo` interface and adding `ValidatesOnDataErrors` did the trick.
<TextBox Name="Value2TextBox">
<TextBox.Text>
<BindingPath Path="Value2" UpdateSourceTrigger="PropertyChanged" ValidatesOnDataErrors="True" />
</TextBox.Text>
</TextBox>
Problem
How would I create a validation rule to ensure Value2 has the same value as Value1? If a validation rule is not the best method then what would be better? I could have the TextChanged event handle this, but I'm wondering if there is something more elegant. ``` <TextBox Name="Value1TextBox"> <TextBox.Text> <BindingPath Path="Value1" UpdateSourceTrigger="PropertyChanged" /> </TextBox.Text> </TextBox> <TextBox Name="Value2TextBox"> <TextBox.Text> <BindingPath Path="Value2" UpdateSourceTrigger="PropertyChanged" /> </TextBox.Text> </TextBox> ```