Live Chat Icon For mobile
Live Chat Icon

How do I update the source as I type in a TextBox?

Platform: WPF| Category: DataBinding

The source can be updated using the ‘UpdateSourceTrigger’ property of the TextBox. By default, the ‘UpdateSourceTrigger’ property is set to ’LostFocus’, i.e. the source is updated when the data-bound TextBox loses the focus. By setting the ‘UpdateSourceTrigger’ property to ’PropertyChanged’, the source will be updated as you type in a TextBox.

In the following code snippet a TextBox’s ‘Text’ property is bound with the Button’s ‘Width’ property. On changing the Text in the TextBox, the Width of the Button is updated.

[XAML]

<Button Name='hellobtn' Content='Hello' Width='150' Height='30'/>
<TextBox Text='{Binding ElementName=hellobtn, Path=Width, Height='20' UpdateSourceTrigger=PropertyChanged}'/>

Share with

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.