2009-12-07 42 views
1

由於ValiationRule不是DependencyObject,因此無法在ValidationRule屬性上使用數據綁定的最佳解決方案是什麼?WPF - ValidationRule不是DependencyObject的解決方法

下面是我會做什麼的一個例子like要做。我希望能夠驗證文本框中的文本對其他一些DependencyProperty。

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

回答

1

您可以使用Josh Smith的virtual branch approach

+0

我會試試這個。 – 2009-12-07 20:03:43

+1

我在文章中掛起的一件事是如何將我的控件的DataContext更新爲,因爲我已經有DataContext =「{Binding RelativeSource = {RelativeSource self}}」。有任何想法嗎? – 2009-12-07 20:20:06

+0

我在這裏問了另一個相關的問題:http://stackoverflow.com/questions/1864432/wpf-how-to-set-datacontext-on-virtual-branch-of-logical-tree – 2009-12-08 03:48:13