【问题标题】:WPF - Workaround for ValidationRule not being a DependencyObjectWPF - ValidationRule 不是 DependencyObject 的解决方法
【发布时间】:2009-12-07 19:17:00
【问题描述】:

由于 ValiationRule 不是 DependencyObject,因此无法对 ValidationRule 属性使用数据绑定的最佳解决方案是什么?

以下是我希望 做的一个示例。我希望能够根据其他一些 DependencyProperty 验证 TextBox 中的文本。

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

【问题讨论】:

    标签: c# .net wpf data-binding xaml


    【解决方案1】:

    您可以使用 Josh Smith 的 virtual branch approach

    【讨论】:

    • 我在文章中挂断的一件事是如何将我的控件的 DataContext 更新为 因为我已经有 DataContext="{Binding RelativeSource={RelativeSource self}}"。有什么想法吗?
    • 我在这里问了另一个相关问题:stackoverflow.com/questions/1864432/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-06
    • 2013-08-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-13
    相关资源
    最近更新 更多