I have a WP7 app (Silverlight) that has a page with a textbox that is bound (TwoWay) to a property on the viewmodel which gets the value from a Linq to Sql database. It all works except when I change the value of the textbox, it sets everything correctly but does not call the SubmitChanges of the datacontext and therefore does not get saved. Is this a normal scenario? Should I do it differently? Is there a way to tell two-way binding that it has to call the SubmitChanges method? Thanks.
Share
You shouldn’t bind a text-box directly to a database. So if you’re not using a ViewModel that implements
INotifyPropertyChanged, but instead bind directly to a linq2sql entity class, you’re doing it wrong.Wrap the properties you wish to expose to the UI in a ViewModel, and call
SubmitChanges()in yourPropertyChangedevent handler.Of course, the best approach is to have a “natural saving point”, such as if you have a page-change (like for OneNote/Office), or a Save Button.