不带绑定的验证规则
我想在文本框上使用 ValidationRules (及其 UI 效果),而不实际将任何内容绑定到文本框。
我想将文本框用于某些不绑定到任何内容但需要在焦点丢失后使用 ValidationRules 验证输入的输入。
能做到吗?
<TextBox.Text>
<Binding Path="" UpdateSourceTrigger="LostFocus">
<Binding.ValidationRules>
<local:IntegersOnlyValidator/>
</Binding.ValidationRules>
</Binding>
</TextBox.Text>
I want to use the ValidationRules (and it's UI effects) on the textbox without actually binding anything to the textbox.
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.
Can it be done?
<TextBox.Text>
<Binding Path="" UpdateSourceTrigger="LostFocus">
<Binding.ValidationRules>
<local:IntegersOnlyValidator/>
</Binding.ValidationRules>
</Binding>
</TextBox.Text>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这对我有用:
This worked for me:
您的代码隐藏应尽可能独立于 GUI,因此我建议您创建一个属性并绑定到该属性。当您想要将文本传递给方法时,只需传递属性的值即可。
Your code-behind should be as independent of the GUI as possible, so I would recommend you to create a property and bind to that. When you want to pass the text to the method, just pass the value of the property.
您可以绑定到任何字符串,例如创建一个字符串作为绑定的源:
You could bind to just any string, e.g. create one as the source for the binding: