简体   繁体   English

WPF-ValidationRule不是DependencyObject的解决方法

[英]WPF - Workaround for ValidationRule not being a DependencyObject

What is the best solution for not being able to use data binding on a ValidationRule property since ValiationRule is not a DependencyObject? 由于ValiationRule不是DependencyObject,因此无法对ValidationRule属性使用数据绑定的最佳解决方案是什么?

Below is an example of what I would like to do. 下面是我去做的例子。 I want to be able to validate the text in the TextBox against some other DependencyProperty. 我希望能够针对某些其他DependencyProperty来验证TextBox中的文本。

<TextBox Name="myTextBox">
    <TextBox.Text>
        <Binding Path="MySource" UpdateSourceTrigger="PropertyChanged">
            <base:EqualsRule Target="{Binding MyTarget}" />
        </Binding>
    </TextBox.Text>
</TextBox>

您可以使用Josh Smith的虚拟分支方法

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM