O'Reilly logo

Windows® Phone 8 Unleashed by Daniel Vaughan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Validating a TextBox as the User Types

The BindingExpression class’s UpdateSource method forces the target property value to be assigned to its source property. This allows you to perform input validation while the user is entering text into a TextBox, rather than after the TextBox loses focus.

I have created a class called UpdateSourceTriggerExtender, which contains an attached property that is used to trigger an update of the binding source whenever the TextBox’s text changes.

When the attached property is placed on a TextBox, the UpdateSourceTriggerExtender class’s HandleUpdatePropertyChanged method is called, which subscribes to the TextBox.TextChanged event (see Listing 26.1). When the text is changed the BindingExpression for the TextProperty ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required