Kevin
Kevin

Reputation:

WPF (MVVM) databinding issue

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}"/>

Wwhen 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.

Upvotes: 0

Views: 346

Answers (3)

Eli Dagan
Eli Dagan

Reputation: 848

Use Snoop to check if you have an error bindings on the TextBox text property. most of the time you can get a pretty good idea of what really happens when you use it

Upvotes: 0

Jeff Wain
Jeff Wain

Reputation: 1022

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

Upvotes: 2

Andy
Andy

Reputation: 30418

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}"/>

Upvotes: 1

Related Questions