私は WPF に手を出していて、今まで見たことのない特異性に気付きました。以下の例では、コード ビハインドで同じ DP にバインドされた 2 つのテキスト ボックスがあります。
分離コード:
public partial class MainWindow : Window
{
public string Text
{
get { return (string)GetValue(TextProperty); }
set { SetValue(TextProperty, value); }
}
public static readonly DependencyProperty TextProperty =
DependencyProperty.Register("Text", typeof(string), typeof(Window), new FrameworkPropertyMetadata("Hello"));
public MainWindow()
{
InitializeComponent();
}
}
そしてXAML:
<TextBox>
<TextBox.Text>
<Binding RelativeSource = "{RelativeSource Mode=FindAncestor, AncestorType=Window}" Path="Text" UpdateSourceTrigger="PropertyChanged" Mode="TwoWay">
<Binding.ValidationRules>
<utils:RestrictInputValidator Restriction="IntegersOnly" ValidatesOnTargetUpdated="True"/>
</Binding.ValidationRules>
</Binding>
</TextBox.Text>
</TextBox>
<TextBox Name="TextBox" Text="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Window}, Mode=TwoWay, Path=Text, UpdateSourceTrigger=PropertyChanged}"/>
検証に失敗した IntegerOnly 検証 (この場合は整数ではないもの) を含む TextBox に何かを入力すると、基になる Text 変数が更新されないことに気付きました。これはデフォルトの動作ですか? なぜこれを行うのですか?オーバーライドすることは可能ですか?