views:

89

answers:

1

What I would like to do is pretty simple. Given textboxes for ItemPrice, Tax and Total, I need the text value for Total to be bound to ItemPrice + Tax and the Tax value to display ItemPrice * taxRate.

Could someone offer a brief explanation as to how this would be accomplished or point me to an appropriate example? I see property binding examples all over the place, but none that show binding to a calculation of the properties of two controls.

+1  A: 

This can be done quite simply: bind the Text property of the Total box to another property on your ViewModel, all that property does is have a getter that returns the sum of ItemPrice and Tax.

You don't need to bind the Total box to any other control. Just make sure that your ViewModel also implements INotifyPropertyChanged, and that you also notify that the Total property has changed when ItemPrice or Tax have changed (so that your bound text automatically updates).

slugster
+1: Something that has properties such as `ItemPrice` and `Tax` really ought to be using a ViewModel. However it may worth mentioning what a ViewModel is since the OP doesn't mention one already in place.
AnthonyWJones