本文介绍了ValidationRules没有绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在文本框上使用ValidationRules(和它的UI效果),而不会实际绑定到文本框。

I want to use the ValidationRules (and it's UI effects) on the textbox without actually binding anything to the textbox.

我想将文本框用于一些不受任何限制的输入,但需要使用ValidationRules在焦点丢失后验证输入。

I want to use the textbox for some input that doesn't bound to anything but need to validate the input after focus is lost using the ValidationRules.

可以完成吗?

<TextBox.Text>
   <Binding Path="" UpdateSourceTrigger="LostFocus">
     <Binding.ValidationRules>
        <local:IntegersOnlyValidator/>
     </Binding.ValidationRules>
   </Binding>
 </TextBox.Text>


推荐答案

这对我有用:

<TextBox.Text>
    <Binding RelativeSource="{RelativeSource Self}" Path="Text" UpdateSourceTrigger="LostFocus">
      <Binding.ValidationRules>
        <Filters:IntegersOnlyValidator/>
      </Binding.ValidationRules>
   </Binding>
 </TextBox.Text>

这篇关于ValidationRules没有绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-14 18:48