Behavior to force TextBox model update to prevent trouble with the ApplicationBar
2/2/2012source: Joost van Schaik`s blog
A small quicky this time:
Problem:
- TextBox, Text property bound to a string in my ViewModel
- I type text in the TextBox
- I click a "Save" button on my ApplicationBar
- The string in my ViewModel is not updated. It never gets updated. WTF???
It appears the TextBox only updates it's value to a bound string when it loses focus. And a TextBox does not lose focus when you click an ApplicationBar Button. Meh.
I have found a few solutions and workarounds, and in the end rolled my own: a very small behavior that updates the binding every time you type something in your textbox. That's a bit wasteful, but it works for me. It builds on the SafeBehavior pattern I wrote about earlier, and it's so small I post it in one go:
...Read more
You can also follow us on Twitter @winphonegeek
Comments
use rx
posted by: dotnetnelson on 2/2/2012 10:47:25 AM
Consider using rx to only update the binding after the user has stopped typing for a few ms
New! WindowsPhoneGeek Component Marketplace
Our Top Articles & Free books
- Our FREE e-book: "Windows Phone Toolkit In Depth" 2nd edition
- 400+ Windows Phone Development articles in our Article Index
- 21 WP7 Toolkit in Depth articles covering all controls
- 12 WP7 Coding4Fun Toolkit in Depth articles covering all controls
- Performance Tips when creating WP7 apps
- Creating a WP7 Custom Control in 7 Steps
- WP7 working with VisualStates: How to make a ToggleSwitch from CheckBox
- What makes a WP7 App successful
- Creating theme friendly UI in WP7 using OpacityMask
- Implementing Windows Phone 7 DataTemplateSelector and CustomDataTemplateSelector
Our Top Tips & Samples
- All about WP7 Isolated Storage series
- WP7 Dynamically Generating DataTemplate in code
- 5 tips for a successful WP7 Marketplace submission
- WP7: Navigating to a page in different assembly
- WP7 ContextMenu: answers to popular questions
- WP7 ListBox: answers to popular questions
- WP7 working with Images: Content vs Resource build action
- WP7 Element Binding samples
- WP7 working with XML: reading, filtering and databinding
- Drawing in WP7: #2 Drawing shapes with finger
- WP7 TextBox Light theme problems - the solution
- Changing the WP7 Panorama Background Image dynamically with Animation
