Coding | .NET | C♯ | Angular | Ionic | Cordova | :-o

Menu

UpdateSource: Extension Method

Introduction

You use UpdateSource on binding expressions to manually update the source. You usually do this to differ default update behavior. For example, if you have a TextBox and you have bound TextBox.Text property with your data object’s property, by default the source will update when the TextBox looses focus. In some cases you might want to alter this behavior. For example you want to update the source only when user hits “Save” button. You can achieve this by changing the BindingExpression’s UpdateSourceTrigger property to “Explicit”, and calling UpdateSource on the same BindingExpression from “Save” buttons click EventHandler. For complete code for a similar example head to MSDN

UpdateSource – The Extension Method

I shifted UpdateSource related code to an extension method for FrameworkElement to make it easier to call UpdateSource of the property directly from the FrameworkElement. You can utilize this method on all FrameworkElements throughout the project. So, in the example above, in EventHandler for button’s click, you could just call UpdateSource on the TextBox like this: