Enforce validation on a TexBox when text changes i

2019-03-01 12:58发布

I'm using Validation on TextBox as follows

<TextBox BorderThickness="1" Style="{DynamicResource TextBoxInError}"
Validation.ErrorTemplate="{StaticResource ValidationTemplate}">
     <TextBox.Text>
         <Binding Path="TimeBeforeDeletingPicture" Mode="TwoWay">
              <Binding.ValidationRules>
                   <helpers:TimeBeforeDeletingRule/>
              </Binding.ValidationRules>
         </Binding>
     </TextBox.Text>
</TextBox>

The validation fires when I leave the TextBox (apparently when it looses focus), I want to validate the input every time the text changes, I'm using MVVM so I don't want to mess with events, what's the correct clean way to achieve that.

1条回答
Luminary・发光体
2楼-- · 2019-03-01 13:38

Set UpdateSourcetrigger as follows

 <TextBox.Text>
            <Binding Path="TimeBeforeDeletingPicture" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged"/>
查看更多
登录 后发表回答