1

ユーザーがコントロールからタブアウトしたときにテキストボックスに特定の文字列を追加するようにしたいのですが、つまりLostFocusですが、ユーザーが入力したときにテキストボックスを検証することをお勧めします。そのため、UpdateSourceTriggerに設定しPropertyChangedます。

これをWPFで機能させる方法はありますか?

似ているが、よりクリーンな解決策があるかどうか疑問に思っているこの質問を見てください。

私のXAMLは次のとおりです。

    <TextBox Text="{Binding Path=MyBindingPath, 
                            StringFormat='\{0} -HELLO',
                            TargetNullValue={x:Static sys:String.Empty},
                            ValidatesOnDataErrors=True,   
                            NotifyOnValidationError=True,    
                            UpdateSourceTrigger=PropertyChanged}"/>
4

1 に答える 1

1

UpdateSourceTrigger を Explicit に設定し、TextBox の TextChanged イベント ハンドラーで、必要なことを実行した後に UpdateSource を明示的に呼び出すことができます。

//write the code you want to run first and then the following code
BindingExpression exp = this.textBox1.GetBindingExpression(TextBox.TextProperty);
exp.UpdateSource();
于 2009-12-23T17:06:23.260 に答える