Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
问候,如何验证 TextBlock 中的值是否正常?我有一个文本框,我在其中绑定“金额”属性和一个使用多重绑定的文本块:价格属性和金额属性。我想做这样的事情:如果更改金额,我想验证价格是否大于 xx(这是常数)。提前致谢
您已经为绑定验证创建了验证规则类(从验证规则派生)。这是一些如何在 WPF 中实现绑定验证的示例
样品 1
样品 2
我知道如何创建验证规则。当其他控件(TextBox)中的值发生变化时,我只想在我的TextBlock中触发验证。
XAML 中有一个简单的标志来设置何时进行验证。
<'local:ValidationRules ValidatesOnTargetUpdated="True" />
希望有帮助。