tags:

views:

145

answers:

2

hi All,

when I bind a property in the child viewmodel to a textbox, the source won't get updated no matter what mode i set on the binding.

the xaml code is like this:

<TextBox Text="{Binding Path=OrderDetail.CashPaid, Mode=TwoWay}"/>

when the view loaded, the binding system query the CashPaid property once. but whenever the text is edited, the value won't update the source. I must missing something here or the WPF databinding system does not support this kind of binding.

thx

Kevin

+1  A: 

By default, TextBox will only update the source of the binding when focus leaves the control. If you set UpdateSourceTrigger to PropertyChanged, the property will be updated as the user types:

<TextBox Text="{Binding Path=OrderDetail.CashPaid, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
Andy
Yes, i try setting UpdateSourceTrigger=PropertyChanged, no luck.
+2  A: 

You also need to make sure OrderDetail implements INotifyProperty changed and make sure that your CashPaid property is notified when it changes. See the MSDN doc for more info on this one.

http://msdn.microsoft.com/en-us/library/system.componentmodel.inotifypropertychanged.aspx

Jeff Wain
See also "How to: Implement the INotifyPropertyChanged Interface": http://msdn.microsoft.com/en-us/library/ms229614.aspx
emddudley
yes, I have INotifyProperty interface implemented and raise the event at the setter. for the regular binding e.g. just bind to the current datacontext/viewmodel property, it works fine. the only difference is where the property reside. I even try to set the dataContext on the textbox to OrderDetail and set the text binding normally, doesn't make any difference.
In that case, try setting BindsDirectlyToSource=true and see if it changes anything. Also, is the CashPaid property a string? If not, it can't bind TwoWay without a IValueConverter.
Jeff Wain
I think Jeff may have hit on it: "CashPaid" sounds like either a boolean or a numeric. Binding will employ ToString() without the converter, so it may appear to be bound correctly. To convert back, you'll need to implement both methods of IValueConverter.
Joel Cochran