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 ...
Get Windows® Phone 8 Unleashed now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.