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 tha开发者_运维问答t show binding to a calculation of the properties of two controls.
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).
精彩评论