强制在TexBox验证时,文本在WPF的变化 [英] Enforce validation on a TexBox when text changes in WPF
本文介绍了强制在TexBox验证时,文本在WPF的变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我用验证
在文本框如下:
<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>
当我离开文本框(显然,当它失去焦点),我想验证验证大火输入文字的变化,我每次使用 MVVM
,所以我不希望与事件一塌糊涂,什么是正确的清洁方式来实现这一点。
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.
推荐答案
设置UpdateSourcetrigger如下:
Set UpdateSourcetrigger as follows
<TextBox.Text>
<Binding Path="TimeBeforeDeletingPicture" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged"/>
这篇关于强制在TexBox验证时,文本在WPF的变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文