我试图理解为什么如果我不调用ValidationRule
基本构造函数,比如
public GrainWeightValidate() : base(ValidationStep.UpdatedValue, true) { }
然后当应该调用验证规则时LostFocus
(使用TextBox
如下所示),当确实失去焦点时,根本Validate
不会调用该函数。但是,如果我在下面更改为, then会被调用,但会无限调用,直到堆栈溢出。以下是相关的 XAML:TextBox
UpdateSourceTrigger
PropertyChanged
GrainWeightValidate.Validate()
<Viewbox Grid.Row="1" Grid.Column="4">
<AdornerDecorator>
<TextBox Name="GrainWeightTextBox" MinWidth="23">
<TextBox.Text>
<Binding RelativeSource="{RelativeSource Self}" Path="Text" UpdateSourceTrigger="LostFocus">
<Binding.ValidationRules>
<local:GrainWeightValidate/>
</Binding.ValidationRules>
</Binding>
</TextBox.Text>
</TextBox>
</AdornerDecorator>
</Viewbox>